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_TOKENOPENAI_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
/newbotto 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
- Cristobal Carnero Linan - ccarnerolinan@gmail.com
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.3.0.tar.gz
(4.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
gptel-0.3.0-py3-none-any.whl
(6.0 kB
view details)
File details
Details for the file gptel-0.3.0.tar.gz.
File metadata
- Download URL: gptel-0.3.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53ecb48d90174f62b51e9f6bdd62ea292c8573b0eba236de3eeed1202ec4a8a6
|
|
| MD5 |
e984405f395cb014902bb05144b8c893
|
|
| BLAKE2b-256 |
25d6684c6311c5cfea06bea5a8fd429c99dc812050dec850da53e200f0638908
|
File details
Details for the file gptel-0.3.0-py3-none-any.whl.
File metadata
- Download URL: gptel-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac8b8200da028a0d9d5645a218c612603572f119735e04a7d3384697076a2d19
|
|
| MD5 |
6fcd24835195ddf78ee9b3220952510e
|
|
| BLAKE2b-256 |
6694b1ac10009c4f04b06c9a19b0e4f247a72c243de6aa6c1b7156e528cdf842
|