Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathechoBot.py
More file actions
Latest commit
39 lines (33 loc) · 1.19 KB
/
Copy pathechoBot.py
File metadata and controls
39 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
importjson
fromtelegram.extimportUpdater, CommandHandler, MessageHandler, Filters
frombotimizeimportBotimize
# Declare updater & dispatcher
telegram_bot_token='Your_Telegram_Token'
updater=Updater(token=telegram_bot_token)
dispatcher=updater.dispatcher
# Declare Botimize
botimize_apiKey='Your_Botimize_Api_Key'
botimize=Botimize(botimize_apiKey, 'telegram')
# Customize function
defstart(bot, update):
bot.sendMessage(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
defresp(bot, update):
echo_response=update.message.text
bot.sendMessage(chat_id=update.message.chat.id, text=echo_response)
# botimize incoming
botimize.log_incoming(update.to_dict())
# botimize outgoing
outgoingLog= {
'token': telegram_bot_token,
'chat_id': update.message.chat.id,
'text': echo_response
}
botimize.log_outgoing(outgoingLog)
# Structuralize bot (custom functions -> dispatcher)
start_handler=CommandHandler('start', start)
echo_handler=MessageHandler(Filters.text, resp)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(echo_handler)
# Update to telegram platfrom
updater.start_polling()
updater.idle()