Skip to content

3cky/pyTelegramBotAPI

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot API (unofficial) in Python 3

An implementation of the Telegram Bot API messages and some simple clients.

Used by:

  • aioTelegramBot - An easily customisable bot written in asyncio Python3. * txTelegramBot - An easily customisable bot written in Twisted Python3.

Installation

pip3 install TelegramBotAPI

Usage

Requests Client

from TelegramBotAPI.client.requestsclient import RequestsClient
from TelegramBotAPI.types.methods import getUpdates, sendMessage

# setup
client = RequestsClient(_token)

# send_message
msg = sendMessage()
msg.chat_id = _user_id
msg.text = 'hello there'

resp = client.send_method(msg)
print(resp)


# poll updates
msg = getUpdates()
msg.timeout = _timeout
msg.limit = _limit
msg.offset = last_id + 1

updates = client.send_method(msg)

for update in updates:
    print(update)

Python asyncio Client

import asyncio

from TelegramBotAPI.client.asyncioclient import AsyncioClient
from TelegramBotAPI.types.methods import getUpdates, sendMessage


@asyncio.coroutine
def main():
    client = AsyncioClient(_token)

    # send message
    msg = sendMessage()
    msg.chat_id = _user_id
    msg.text = 'hello there'

    resp = yield from client.send_method(msg)
    print(resp)

    # poll updates
    msg = getUpdates()
    msg.timeout = _timeout
    msg.limit = _limit
    msg.offset = last_id + 1

    updates = yield from client.send_method(msg)

    for update in updates:
        print(update)

About

Telegram Bot API (unofficial) in Python 3

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 97.8%
  • Makefile 1.2%
  • Shell 1.0%