Skip to main content

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(
    name="TestBot",
    description="A bot to test GPTel framework",
    data_default={"flag": False},
)


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


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


@bot.command("switch", "Switch flag")
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", "Show an 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()

To run it:

# Set up name, description and button menu of the bot:
python main.py --setup

# Run the bot:
python main.py

Install

pip install gptel

Setup

You need to setup two environment variables:

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

To get a new Telegram token for your bot:

  • Open Telegram: Search for @BotFather.
  • Start a Chat: Click "Start" to begin a conversation with BotFather.
  • Create Bot: Send /newbot to BotFather.
  • Choose Name: Enter a name for your bot when prompted.
  • Set Username: Provide a unique username ending in "bot".
  • Receive Token: BotFather will give you the bot's token. Keep it secure.

Authors

Metadata

Release files for gptel 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 gptel 0.3.0
File Size Uploaded
gptel-0.3.0.tar.gz 4.8 kB Details

Built distribution (wheel)

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

Total release size: 10.8 kB

Release files / gptel-0.3.0.tar.gz

Download URL gptel-0.3.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
53ecb48d90174f62b51e9f6bdd62ea292c8573b0eba236de3eeed1202ec4a8a6
BLAKE2b-256 checksum
How to use checksums
25d6684c6311c5cfea06bea5a8fd429c99dc812050dec850da53e200f0638908
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1015-azure

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

Download URL gptel-0.3.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac8b8200da028a0d9d5645a218c612603572f119735e04a7d3384697076a2d19
BLAKE2b-256 checksum
How to use checksums
6694b1ac10009c4f04b06c9a19b0e4f247a72c243de6aa6c1b7156e528cdf842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1015-azure

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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