
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
python-telegram-bot-api
Advanced tools
Simple and fast client to call rest-api endpoints `api.telegram.org` using `aiohttp` package.
Simple and fast client to call rest-api endpoints api.telegram.org
using aiohttp package.
View at: https://pypi.org/project/python-telegram-bot-api/
pip3 install python-telegram-bot-api
Main example:
import asyncio
from api_tgbot import TgBot, TgException
TGBOT_TOKEN = "12345:YOUR_TOKEN"
APP_HOSTNAME = "https://YOUR_HOSTNAME.ngrok.io"
CHAT_ID = 123456789 # your chat id
client_tgbot = TgBot(token=TGBOT_TOKEN)
async def main_async():
try:
response = await client_tgbot.setWebhook("{hostname}/tgbot/wh".format(hostname=APP_HOSTNAME))
assert type(response) == bool
assert response == True
except TgException as e:
print(e)
try:
sent_msg = await client_tgbot.sendMessage(CHAT_ID, "Hello from Telegram Bot!")
assert sent_msg.chat.id == CHAT_ID
print(sent_msg.text)
except TgException as e:
print(e)
if __name__ == "__main__":
asyncio.run_until_complete(main_async())
Simple JSON-Example if you are not interested in pydantic models and want to use dict in answers:
import asyncio
from api_tgbot import TgBotJson
TGBOT_TOKEN = "12345:YOUR_TOKEN"
APP_HOSTNAME = "https://YOUR_HOSTNAME.ngrok.io"
CHAT_ID = 123456789 # your chat id
client_tgbot = TgBotJson(token=TGBOT_TOKEN)
async def main_async():
response = await client_tgbot.setWebhook("{hostname}/tgbot/wh".format(hostname=APP_HOSTNAME))
print(response.status) # 200
print(response.payload) # {'ok': True, 'result': True, 'description': 'Webhook was set'}
response = await client_tgbot.sendMessage(CHAT_ID, "Hello from Telegram Bot!")
print(response.status) # 200
print(response.payload) # {'ok': True, 'result': {'message_id': 786, 'from': {'id': ... } ... }
if __name__ == "__main__":
asyncio.run_until_complete(main_async())
This package depends on devtud / pygramtic >= 0.2.0 package.
This project and its author is neither associated, nor affiliated with Telegram in anyway. See License section for more details.
This project is released under the GNU LESSER GENERAL PUBLIC LICENSE License.
FAQs
Simple and fast client to call rest-api endpoints `api.telegram.org` using `aiohttp` package.
We found that python-telegram-bot-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.