botimize - Analytics built to optimize your bots
Table of contents
Setup
-
Create a free account at Botimize to get an API key. Or you can talk to our botimize helper Facebook Messenger Helper or Telegram Helper to create a public project.
-
Install botimize SDK with
pip
:pip install botimize
Usage
Initialization
Use Botimize API key to create a new botimize object, and <PLATFORM>
should be facebook
, telegram
, line
or generic
.
from botimize import Botimize
botimize = botimize.Botimize(<YOUR-API-KEY>, <PLATFORM>)
botimize = botimize.Botimize('NS1W0O5YCIDH9HJOGNQQWP5NU7YJ0S0S', 'facebook')
Log incoming messages:
To log incoming message is very easy, just put the body received from platform webhook into log_incoming()
.
Facebook / Telegram / LINE
botimize.log_incoming(request.body)
Generic
incoming_log = {
'sender': {
'id': 'UNIQUE_USER_ID',
'name': 'USER_SCREEN_NAME'
},
'content': {
'type': 'CONTENT_TYPE', #'text', 'image', 'audio', 'video', 'file', 'location'
'text': 'CONTENT_TEXT'
}
}
botimize.log_incoming(incoming_log)
Log outgoing messages
This is a little different from log_incoming()
because outgoing messages have token for sending message to client. "Fortunately", there are three platforms and have three differents ways to authorize by using token. "Unfortunately", one easy way is all Botimize needs.
outgoing_log = {
'recipient': { 'id': '1487766407960998' },
'message': 'hello facebook messenger',
'accessToken': 'EAAXUgsVmiP8BAMcRWxLa1N5RycMzZBfjwiekoqCik6pZASPsnmkJtG29gp5QXdyMaKfFg0iZCIDlqhfhTZCLqRKuM4hUCfdZBcxl8GzKgZA0AwI8syxG49M9OaZCsjyZC8FPg30yIRDFG5hp9jNNtvqtWW0KKzB9a59rTkZBsgz2oe4QZDZD'
}
botimize.log_outgoing(outgoing_log)
Telegram
outgoing_log = {
'chat_id': '161696362',
'text': 'hello telegram',
'token': '308726257:AAHnmJpvkAepqirk82ZOrgtF6Hz2ijbRavA',
}
botimize.log_outgoing(outgoing_log)
LINE
outgoing_log = {
'replyToken': '9bd439c6961346d7b2ec4184469b9946',
'messages': [{
'type': 'text',
'text': 'hello, this is a message from LINE chatbot',
}],
'channelAccessToken': 'GxvuC0QfatJ0/Bv5d3DoVbUcfVd6MXLj9QY8aFHSqCOdkfjD1I5dtbKZBNMbmLmwKox1Ktd0Kcwfsxm9S5OmIwQoChcV1gPlK/1CI8cUe3eqaG/UrqL65y1Birb6rnssT0Acaz+7Lr7V2WVnwrQdB04t89/1O/w1cDnyilFU=',
}
botimize.log_outgoing(outgoing_log)
Generic
outgoing_log = {
'receiver': {
'id': 'UNIQUE_USER_ID',
'name': 'USER_SCREEN_NAME'
},
'content': {
'type': 'CONTENT_TYPE', #'text', 'image', 'audio', 'video', 'file', 'location'
'text': 'CONTENT_TEXT'
}
}
botimize.log_outgoing(outgoing_log)
References & Full Examples
References
- facebook-incoming-message
- facebook-outgoing-message
- telegram-incoming-message
- telegram-outgoing-message
- line-incoming-message
- line-outgoing-message