Skip to main content

Abstraction Layer Over Telegram's Bot API and MTProto Chat Potocols

Project description

contributions:

Please join https://github.com/datamachine/twx

issues:

Please use https://github.com/datamachine/twx/issues

Python version supported:

3.4

TWX is a python interface for the Telegram bot API. It supports making synchronous and asynchronous calls and converts the response into a usable native python object.

Support for the MTProto API is in the works, but considered pre-alpha right now.

Install

For stable:

pip install twx

For dev:

pip install -i https://testpypi.python.org/pypi twx

Quick Start

from twx.botapi import TelegramBot, ReplyKeyboardMarkup

"""
Setup the bot
"""

bot = TelegramBot('<API TOKEN>')
bot.update_bot_info().wait()
print(bot.username)

"""
Send a message to a user
"""
user_id = int(<someuserid>)

result = bot.send_message(user_id, 'test message body').wait()
print(result)

"""
Get updates sent to the bot
"""
updates = bot.get_updates().wait()
for update in updates:
    print(update)

"""
Use a custom keyboard
"""
keyboard = [
    ['7', '8', '9'],
    ['4', '5', '6'],
    ['1', '2', '3'],
         ['0']
]
reply_markup = ReplyKeyboardMarkup.create(keyboard)

bot.send_message(user_id, 'please enter a number', reply_markup=reply_markup).wait()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twx-0.5a5.zip (10.1 kB view details)

Uploaded Source

Built Distribution

twx-0.5a5-py3.4.egg (15.7 kB view details)

Uploaded Source

File details

Details for the file twx-0.5a5.zip.

File metadata

  • Download URL: twx-0.5a5.zip
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for twx-0.5a5.zip
Algorithm Hash digest
SHA256 27c898e5d9c8bb8d87791eaeaa6e3dbc33da9f3f09fc24750e6c3488bda72083
MD5 dd255b3dc68be3123885084cd19b7c03
BLAKE2b-256 b71268694603d2699ef77489160866324520e930211c973f60b79104748c4a19

See more details on using hashes here.

File details

Details for the file twx-0.5a5-py3.4.egg.

File metadata

  • Download URL: twx-0.5a5-py3.4.egg
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for twx-0.5a5-py3.4.egg
Algorithm Hash digest
SHA256 37df8219a7430b9cd494c2653a45fa3fb884e1580227cd7ed8dea3fe3233d4eb
MD5 b82c2b62980abc9c15bb5dfe0cf7fe33
BLAKE2b-256 5c594546f9e8f1598f12853c15c337478cbd617f1b10e6f44d382c383001673f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page