TamTam Bot API library
Project description
ttbotapi
TamTam Bot API library
How to Use
The Bot class encapsulates all API calls in a single class. It provides functions such as
send_xyz
(send_message
, edit_message
etc.) and several ways to listen for incoming messages.
Create a file called echo_bot.py
.
Then, open the file and create an instance of the Bot class.
import ttbotapi
import logging
ttbotapi.logger.setLevel(logging.DEBUG)
# Note: Make sure to actually replace TOKEN with your own API token.
bot = ttbotapi.Bot(access_token='Bot Token')
# After that declaration, we need to register some so-called decorator handlers.
# Update handlers define filters which a message must pass. If a message passes the filter,
# the decorated function is called and the incoming message is passed as an argument.
# Let's define a message handler which handles incoming `/start` and `/help` bot_command in dialog chat type.
@bot.update_handler(chat_type='dialog', bot_command=['/start', '/help'])
def send_welcome(update):
# A function which is decorated by an update handler can have an arbitrary name,
# however, it must have only one parameter (the update)
bot.send_message(text="Howdy, how are you doing?", user_id=update.message.sender.user_id, chat_id=None,
link={'type': 'reply', 'mid': update.message.body.mid})
# Let's add another handler
@bot.update_handler(chat_type='dialog', regexp='hi')
def send_hi(update):
bot.send_message(text=f'Hi 👋, {update.message.sender.name}', user_id=update.message.sender.user_id, chat_id=None)
# This one echoes all incoming text messages back to the sender. It uses a lambda function to test a message.
# If the lambda returns True, the message is handled by the decorated function.
# Since we want all messages to be handled by this function, we simply always return True.
@bot.update_handler(func=lambda update: update.message.body.text)
def echo(update):
bot.send_message(text=update.message.body.text, user_id=update.message.sender.user_id, chat_id=None)
# Using long polling now our bot never stop working
bot.polling()
# Alright, that's it! Our source file now looks fine
To start the bot, simply open up a terminal and enter python echo_bot.py
to run the bot!
Test it by sending commands ('/start' and '/help') and arbitrary text messages.
How to Contribute
- You must follow Contributing Guidelines.
- We are committed to providing a friendly community, for more experience read Code Of Conduct.
How to Communicate
You're welcome to drop in and ask questions, discuss bugs and such, Check Communication Methods.
Frequently Asked Questions
- Please ask
Attribution
These Documents are adapted for MA24th Open Source Software, For more information contact me with any additional questions or comments.
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ttbotapi-0.3.0.tar.gz
.
File metadata
- Download URL: ttbotapi-0.3.0.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51e645e571592ebf783928f586030fc995bea6d2f368d1d4e4851a7b31be4319 |
|
MD5 | e423c8a85022f0404dc3cc172d2e6e36 |
|
BLAKE2b-256 | bb2f7cf5c5bb74c385fe3bd7e822932678ce802132e880e25e58dcc7aec6649f |
File details
Details for the file ttbotapi-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: ttbotapi-0.3.0-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d428010a4d1a9bff445e3f0b79c9334dd75459ffc0b9d0488b5d70ac2394078 |
|
MD5 | fad858289a1dd75f40923fa757964622 |
|
BLAKE2b-256 | f05ad76c94f682a18a6ec1529e3cd7aea1584941c0d592dedf86e31a5b126005 |