Add commands suggestions via set_my_commands api method

* add command suggestions via set_my_commands method

* update README to remove manual instructions for bot menu
This commit is contained in:
Dmitry Gordin
2023-03-15 15:55:27 +06:00
committed by GitHub
parent 386e396c0b
commit 2b4d4ad860
2 changed files with 18 additions and 16 deletions
-15
View File
@@ -59,21 +59,6 @@ mv config/config.example.env config/config.env
docker-compose --env-file config/config.env up --build
```
## Configure command hints (optional, but fancy)
At [@BotFather](https://t.me/BotFather), use command `/mybots` -> select your bot -> Edit Bot -> Edit Commands. Then paste the following text to the BotFather:
```
retry - Regenerate last bot answer
new - Start new dialog
mode - Select chat mode
balance - Show balance
help - Show help
```
After that, you will be able to utilize menu shortcuts or receive prompts while entering commands.
## ❤️ Top donations
You can be in this list: <a href="https://github.com/karfly/chatgpt_telegram_bot/blob/main/static/donate/donate.md#%EF%B8%8F-donate" alt="Donate shield"><img src="https://img.shields.io/badge/-Donate-red?logo=undertale" /></a>
+18 -1
View File
@@ -9,8 +9,15 @@ from pathlib import Path
from datetime import datetime
import telegram
from telegram import Update, User, InlineKeyboardButton, InlineKeyboardMarkup
from telegram import (
Update,
User,
InlineKeyboardButton,
InlineKeyboardMarkup,
BotCommand
)
from telegram.ext import (
Application,
ApplicationBuilder,
CallbackContext,
CommandHandler,
@@ -299,11 +306,21 @@ async def error_handle(update: Update, context: CallbackContext) -> None:
except:
await context.bot.send_message(update.effective_chat.id, "Some error in error handler")
async def post_init(application: Application):
await application.bot.set_my_commands([
BotCommand("/new", "Start new dialog"),
BotCommand("/mode", "Select chat mode"),
BotCommand("/retry", "Re-generate response for previous query"),
BotCommand("/balance", "Show balance"),
BotCommand("/help", "Show help message"),
])
def run_bot() -> None:
application = (
ApplicationBuilder()
.token(config.telegram_token)
.concurrent_updates(True)
.post_init(post_init)
.build()
)