-
Notifications
You must be signed in to change notification settings - Fork 0
/
echoBot.py
39 lines (33 loc) · 1.19 KB
/
echoBot.py
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
import json
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from botimize import Botimize
# 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
def start(bot, update):
bot.sendMessage(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
def resp(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()