forked from szastupov/aiotg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
regexp-based inlines and callbacks (szastupov#42)
- Loading branch information
1 parent
73f7cfd
commit 6465a03
Showing
3 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
import json | ||
from aiotg.ext import ExtendedBot | ||
|
||
bot = ExtendedBot(api_token='377308655:AAEUWJSr_0K67SUEQEE57ua5_DEf-TPHZKI') | ||
|
||
|
||
@bot.command(r'/start') | ||
def start(chat, match): | ||
|
||
markup = { | ||
'type': 'InlineKeyboardMarkup', | ||
'inline_keyboard': [ | ||
[{'type': 'InlineKeyboardButton', | ||
'text': 'Button A', | ||
'callback_data': 'buttonclick-A'}, | ||
{'type': 'InlineKeyboardButton', | ||
'text': 'Button B', | ||
'callback_data': 'buttonclick-B'}], | ||
[{'type': 'InlineKeyboardButton', | ||
'text': 'Nohandle Button', | ||
'callback_data': 'no_callback_data'}], | ||
] | ||
} | ||
|
||
chat.send_text('Hello', reply_markup=json.dumps(markup)) | ||
|
||
|
||
@bot.callback(r'buttonclick-(\w+)') | ||
def buttonclick(chat, cq, match): | ||
chat.send_text('You clicked {}'.format(match.group(1))) | ||
|
||
|
||
@bot.default_callback | ||
def unhandled_callbacks(chat, cq): | ||
chat.send_text('Unhandled callback fired') | ||
|
||
|
||
bot.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters