Giter Site home page Giter Site logo

nyimbi / django-telegram-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jlmadurga/django-telegram-bot

0.0 3.0 0.0 87 KB

Django app to write Telegram bots. Just define commands and how to handle them.

License: BSD 3-Clause "New" or "Revised" License

Makefile 2.13% Python 97.59% HTML 0.28%

django-telegram-bot's Introduction

django-telegram-bot

CI:

image

image

Requirements Status

PyPI:

image

Docs:

Documentation Status

Django app to write Telegram bots. Just define commands and how to handle them.

Try Permabots: more stable django app for bots https://github.com/jlmadurga/permabots

NOTE: Just for text messages at this moment.

Documentation

The full documentation is at https://django-telegram-bot.readthedocs.org.

Telegram API documentation at https://core.telegram.org/bots/api

Quickstart

Install django-telegram-bot:

pip install django-telegram-bot

Add telegrambot and rest_framework to your INSTALLED_APPS, and run:

$ python manage.py migrate

After creating a bot in Telegram Platform, create at least one bot with django admin. Token is the only required field. You may need to provided public key certificate for your server. https://core.telegram.org/bots/self-signed Heroku has https and ssl by default so it is a good option if you dont want to deal with that.

Add webhook url to your urlpatterns:

url(r'^telegrambot/', include('telegrambot.urls', namespace="telegrambot")),    

Define the file where commands will be defined in urlpatterns variable, analogue to django urls and ROOT_URLCONF:

TELEGRAM_BOT_HANDLERS_CONF = "app.handlers"

Set bot commands handlers is very easy just as defining urls in django. Module with urlpatterns that list different handlers. You can regex directly or use shortcuts like command or unknown_command :

urlpatterns = [command('start', StartView.as_command_view()),
               command('author', AuthorCommandView.as_command_view()),
               command('author_inverse', AuthorInverseListView.as_command_view()),
               command('author_query', login_required(AuthorCommandQueryView.as_command_view())),
               unknown_command(UnknownView.as_command_view()),
               regex(r'author_(?P<name>\w+)', AuthorName.as_command_view()),
              ]

To set the webhook for telegram you need django.contrib.sites installed, SITE_ID configured in settings and with it correct value in the DB. The webhook for each bot is set when a Bot is saved and enabled field is set to true.

Bot views responses with Telegram messages to the user who send the command with a text message and keyboard. Compound with a context and a template. The way it is handled is analogue to Django views. Visits docs for more details https://django-telegram-bot.readthedocs.io/en/latest/usage.html

Features

  • Multiple bots
  • Message handling definition.
  • Authentication
  • Text responses and keyboards.
  • Media messages not supported.
  • Only Markup parse mode.

image

image

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements/test.txt
(myenv) $ make test
(myenv) $ make test-all

django-telegram-bot's People

Contributors

jlmadurga avatar ihoru avatar ramiro avatar mohammad7t avatar luckydonald avatar

Watchers

James Cloos avatar Nyimbi Odero avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.