Giter Club home page Giter Club logo

asgigram's Introduction

asgigram

An ASGI server for Telegram bots. Connects to the Telegram API using the long-polling getUpdates endpoint, and dispatches incoming updates into an ASGI application following the ASGI protocol specification below.

It is currently very much in beta, and should not be used for production code.

Installation

pip install asgigram

Usage

asgigram "01234567:your_token_here" your_project.asgi:application

ASGI Protocol Specification

The Telegram API is exposed with each chat (including private messages from users) as a separate connection scope, and with different event types for the various kinds of update.

Connection Scope

Connection are "scoped" by the chat identifier, which means in practice you will have a different scope per chat or user. Because the Telegram API is stateless, scopes do not last the lifetime of the user or chat's interaction with the bot.

Instead, the scope and application instance will be made when the user first interacts with the bot after process start, and will be lost either when the user has been inactive for some time and it is garbage-collected or when the current process ends.

If you want to manage long-lasting, per-user state, it's recommended you use a database or some kind of session store.

The scope contains:

  • type: telegram
  • chat: Telegram Chat object, containing at minimum an id key with an integer chat ID.
  • user: Telegram User object, containing at minimum an id key with an integer user ID.

Exactly one of chat or user will be present. Event types below include which type of scope they will occur in.

Message (Incoming)

An incoming message in a chat (channel, group, supergroup, private message).

Keys:

Message (Outgoing)

An outgoing message to a chat.

Keys:

  • type: telegram.send_message
  • text: Unicode string of the text to send.
  • chat_id: Optional integer chat ID to send to or unicode string chat name (in format @chatname). If not provided, will default to the current chat scope. If you are in a user scope, you must provide this.
  • parse_mode: Optional Unicode string with value Markdown or HTML if the value of text is to be treated as a markup language.
  • reply_to_message_id: Optional integer Telegram message ID that this is a reply to.

asgigram's People

Contributors

andrewgodwin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.