Skip to main content

ttbotapi

TamTam Bot API library

GPLv2 license PyPI Python package Upload Python Package

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

Join our channel on TamTam Channel and Discord Server .

Metadata

Release files for ttbotapi 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ttbotapi 0.3.0
File Size Uploaded Provenance Actions
ttbotapi-0.3.0.tar.gz 24.3 kB Without provenance Details for ttbotapi-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ttbotapi 0.3.0
File Interpreter ABI Platform Actions
ttbotapi-0.3.0-py3-none-any.whl Python 3 none any Details for ttbotapi-0.3.0-py3-none-any.whl

Total release size: 50.8 kB

Release files / ttbotapi-0.3.0.tar.gz

Download URL ttbotapi-0.3.0.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
51e645e571592ebf783928f586030fc995bea6d2f368d1d4e4851a7b31be4319
BLAKE2b-256 checksum
How to use checksums
bb2f7cf5c5bb74c385fe3bd7e822932678ce802132e880e25e58dcc7aec6649f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / ttbotapi-0.3.0-py3-none-any.whl

Download URL ttbotapi-0.3.0-py3-none-any.whl
Size 26.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d428010a4d1a9bff445e3f0b79c9334dd75459ffc0b9d0488b5d70ac2394078
BLAKE2b-256 checksum
How to use checksums
f05ad76c94f682a18a6ec1529e3cd7aea1584941c0d592dedf86e31a5b126005
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for ttbotapi 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page