|
| 1 | +# [botimize](http://botimize.io) - Analytics built to optimize your bots |
| 2 | + |
| 3 | + |
| 4 | +## Table of contents |
| 5 | + |
| 6 | +- [Setup](#setup) |
| 7 | +- [Usage](#usage) |
| 8 | +- [Initialization](#initialization) |
| 9 | +- [Log incoming messages](#log-incoming-messages) |
| 10 | +- [Log outgoing messages](#log-outgoing-messages) |
| 11 | +- [References & Full Examples](#references--full-examples) |
| 12 | + |
| 13 | +## Setup |
| 14 | + |
| 15 | +* Create a free account at [Botimize](http://botimize.io) to get an API key. Or you can talk to our botimize helper [Facebook Messenger Helper](http://m.me/botimize.helper) or [Telegram Helper](http://t.me/botimize.helper) to create a public project. |
| 16 | +* Install botimize SDK with `pip`: |
| 17 | + |
| 18 | + ```shell |
| 19 | + pip install botimize |
| 20 | + ``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +### Initialization |
| 25 | + |
| 26 | +Use Botimize API key to create a new botimize object, and `<PLATFORM>` should be `facebook`, `telegram`, `line` or `generic`. |
| 27 | + |
| 28 | + ```python |
| 29 | + from botimize import Botimize |
| 30 | + ``` |
| 31 | + ```python |
| 32 | + botimize = botimize.Botimize(<YOUR-API-KEY>, <PLATFORM>) |
| 33 | + ``` |
| 34 | + ```python |
| 35 | + botimize = botimize.Botimize('NS1W0O5YCIDH9HJOGNQQWP5NU7YJ0S0S', 'facebook') |
| 36 | + ``` |
| 37 | + |
| 38 | +### Log incoming messages: |
| 39 | + |
| 40 | +To log incoming message is very easy, just put the body received from platform webhook into `log_incoming()`. |
| 41 | + |
| 42 | +#### Facebook / Telegram / LINE |
| 43 | + ```python |
| 44 | + botimize.log_incoming(request.body) |
| 45 | + ``` |
| 46 | + |
| 47 | +#### Generic |
| 48 | + ```python |
| 49 | + incoming_log = { |
| 50 | + 'sender': { |
| 51 | + 'id': 'UNIQUE_USER_ID', |
| 52 | + 'name': 'USER_SCREEN_NAME' |
| 53 | + }, |
| 54 | + 'content': { |
| 55 | + 'type': 'CONTENT_TYPE', #'text', 'image', 'audio', 'video', 'file', 'location' |
| 56 | + 'text': 'CONTENT_TEXT' |
| 57 | + } |
| 58 | + } |
| 59 | + botimize.log_incoming(incoming_log) |
| 60 | + ``` |
| 61 | + |
| 62 | +### Log outgoing messages |
| 63 | + |
| 64 | +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. |
| 65 | + |
| 66 | +#### Facebook |
| 67 | + ```python |
| 68 | + outgoing_log = { |
| 69 | + 'recipient': { 'id': '1487766407960998' }, |
| 70 | + 'message': 'hello facebook messenger', |
| 71 | + 'accessToken': 'EAAXUgsVmiP8BAMcRWxLa1N5RycMzZBfjwiekoqCik6pZASPsnmkJtG29gp5QXdyMaKfFg0iZCIDlqhfhTZCLqRKuM4hUCfdZBcxl8GzKgZA0AwI8syxG49M9OaZCsjyZC8FPg30yIRDFG5hp9jNNtvqtWW0KKzB9a59rTkZBsgz2oe4QZDZD' |
| 72 | + } |
| 73 | + botimize.log_outgoing(outgoing_log) |
| 74 | + ``` |
| 75 | + |
| 76 | +#### Telegram |
| 77 | + ```python |
| 78 | + outgoing_log = { |
| 79 | + 'chat_id': '161696362', |
| 80 | + 'text': 'hello telegram', |
| 81 | + 'token': '308726257:AAHnmJpvkAepqirk82ZOrgtF6Hz2ijbRavA', |
| 82 | + } |
| 83 | + botimize.log_outgoing(outgoing_log) |
| 84 | + ``` |
| 85 | + |
| 86 | +#### LINE |
| 87 | + ```python |
| 88 | + outgoing_log = { |
| 89 | + 'replyToken': '9bd439c6961346d7b2ec4184469b9946', |
| 90 | + 'messages': [{ |
| 91 | + 'type': 'text', |
| 92 | + 'text': 'hello, this is a message from LINE chatbot', |
| 93 | + }], |
| 94 | + 'channelAccessToken': 'GxvuC0QfatJ0/Bv5d3DoVbUcfVd6MXLj9QY8aFHSqCOdkfjD1I5dtbKZBNMbmLmwKox1Ktd0Kcwfsxm9S5OmIwQoChcV1gPlK/1CI8cUe3eqaG/UrqL65y1Birb6rnssT0Acaz+7Lr7V2WVnwrQdB04t89/1O/w1cDnyilFU=', |
| 95 | + } |
| 96 | + botimize.log_outgoing(outgoing_log) |
| 97 | + ``` |
| 98 | + |
| 99 | +#### Generic |
| 100 | + ```python |
| 101 | + outgoing_log = { |
| 102 | + 'receiver': { |
| 103 | + 'id': 'UNIQUE_USER_ID', |
| 104 | + 'name': 'USER_SCREEN_NAME' |
| 105 | + }, |
| 106 | + 'content': { |
| 107 | + 'type': 'CONTENT_TYPE', #'text', 'image', 'audio', 'video', 'file', 'location' |
| 108 | + 'text': 'CONTENT_TEXT' |
| 109 | + } |
| 110 | + } |
| 111 | + botimize.log_outgoing(outgoing_log) |
| 112 | + ``` |
| 113 | + |
| 114 | +## References & Full Examples |
| 115 | + |
| 116 | +### References |
| 117 | +* [facebook-incoming-message](https://developers.facebook.com/docs/messenger-platform/webhook-reference#format) |
| 118 | +* [facebook-outgoing-message](https://developers.facebook.com/docs/messenger-platform/send-api-reference#request) |
| 119 | +* [telegram-incoming-message](https://core.telegram.org/bots/api#getting-updates) |
| 120 | +* [telegram-outgoing-message](https://core.telegram.org/bots/api#sendmessage) |
| 121 | +* [line-incoming-message](https://devdocs.line.me/en/#webhook-event-object) |
| 122 | +* [line-outgoing-message](https://devdocs.line.me/en/?shell#reply-message) |
| 123 | + |
| 124 | +### Full Examples |
| 125 | +* [line-python-bot](https://github.com/botimize/line-python-bot) |
| 126 | +* [telegram-node-bot](https://github.com/botimize/telegram-node-bot) |
| 127 | +* [telegram-python-bot](https://github.com/botimize/telegram-python-bot) |
| 128 | +* [messenger-node-bot](https://github.com/botimize/messenger-node-bot) |
| 129 | +* [messenger-python-bot](https://github.com/botimize/messenger-python-bot) |
0 commit comments