Skip to main content

Framework to build Telegram bots

Project description

GPTel

Framework to ease the writing of Telegram bots, using advance features like speach to text.

Example

from gptel import GPTelBot, BotContext, ReplyTyping, ReplyImage


bot = GPTelBot(data_default={"flag": False})


@bot.command("start")
async def command_start(context: BotContext):
    yield rf"Hello {context.user_html}!"


@bot.command("help")
async def command_help(context: BotContext):
    yield r"Help!"


@bot.command("switch")
async def command_switch(context: BotContext):
    # context.data is specific for current chat.
    context.data["flag"] = not context.data["flag"]
    yield r"Switch on!" if context.data["flag"] else r"Switch off!"


@bot.command("image")
async def command_image(context: BotContext):
    yield ReplyTyping()
    # ReplyImage only supports URL at the moment.
    yield ReplyImage("https://picsum.photos/300/300.jpg")


# This will handle both text chat and voice messages, that will be converted automatically
# to text using OpenAI's Whisper.
@bot.chat()
async def echo(context: BotContext, message: str):
    yield ReplyTyping()
    yield r"You said:"
    yield message


bot.run()

Install

pip install gptel

Setup

You need to setup two environment variables:

  • TELEGRAM_TOKEN
  • OPENAI_API_KEY: for the speech to text service.

Authors

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

gptel-0.1.1.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

gptel-0.1.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

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