From 995815e936553aa34574c752df05af842373efea Mon Sep 17 00:00:00 2001 From: kakalan123 Date: Fri, 23 Jun 2017 15:36:58 +0800 Subject: [PATCH 1/6] fix README --- README.md | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.mdown | 101 --------------------------------------- 2 files changed, 130 insertions(+), 101 deletions(-) create mode 100644 README.md delete mode 100644 README.mdown diff --git a/README.md b/README.md new file mode 100644 index 0000000..d998687 --- /dev/null +++ b/README.md @@ -0,0 +1,130 @@ +# [botimize](http://botimize.io) - Analytics built to optimize your bots + + +## Table of contents + +- [Setup](#Setup) +- [Usage](#Usage) +- [Initialization](#Initialization) +- [Log incoming messages](#log-incoming-messages) +- [Log outgoing messages](#log-outgoing-messages) +- [References & Full Examples](#references--full-examples) + +## Setup + +* 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. +* Install botimize SDK with `pip`: + + ```shell + pip install botimize + ``` + +## Usage + +### Initialization + +Use Botimize API key to create a new botimize object, and `` should be `facebook`, `telegram`, `line` or `generic`. + + ```python + from botimize import Botimize + ``` + ```python + const botimize = botimize.Botimize(, ) + ``` + ```python + const 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 + ```python + botimize.log_incoming(request.body) + ``` + +#### Generic + ```python + 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. + +#### Facebook +- For those who already use request to your poject: Put options of request into `logOutgoing()`. + ```python + outgoing_log = { + 'recipient': { 'id': '1487766407960998' }, + 'message': 'hello facebook messenger', + 'accessToken': 'EAAXUgsVmiP8BAMcRWxLa1N5RycMzZBfjwiekoqCik6pZASPsnmkJtG29gp5QXdyMaKfFg0iZCIDlqhfhTZCLqRKuM4hUCfdZBcxl8GzKgZA0AwI8syxG49M9OaZCsjyZC8FPg30yIRDFG5hp9jNNtvqtWW0KKzB9a59rTkZBsgz2oe4QZDZD' + } + botimize.log_outgoing(outgoing_log) + ``` + +#### Telegram + ```python + outgoing_log = { + 'chat_id': '161696362', + 'text': 'hello telegram', + 'token': '308726257:AAHnmJpvkAepqirk82ZOrgtF6Hz2ijbRavA', + } + botimize.log_outgoing(outgoing_log) + ``` + +#### LINE + ```python + 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 + ```python + 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](https://developers.facebook.com/docs/messenger-platform/webhook-reference#format) +* [facebook-outgoing-message](https://developers.facebook.com/docs/messenger-platform/send-api-reference#request) +* [telegram-incoming-message](https://core.telegram.org/bots/api#getting-updates) +* [telegram-outgoing-message](https://core.telegram.org/bots/api#sendmessage) +* [line-incoming-message](https://devdocs.line.me/en/#webhook-event-object) +* [line-outgoing-message](https://devdocs.line.me/en/?shell#reply-message) + +### Full Examples +* [line-python-bot](https://github.com/botimize/line-python-bot) +* [telegram-node-bot](https://github.com/botimize/telegram-node-bot) +* [telegram-python-bot](https://github.com/botimize/telegram-python-bot) +* [messenger-node-bot](https://github.com/botimize/messenger-node-bot) +* [messenger-python-bot](https://github.com/botimize/messenger-python-bot) diff --git a/README.mdown b/README.mdown deleted file mode 100644 index 692fbf5..0000000 --- a/README.mdown +++ /dev/null @@ -1,101 +0,0 @@ -## Setup - -* Create a free account at [botimize](http://botimize.io) to get an API key. - -* Install botimize SDK with pip - ```terminal - pip install botimize - ``` - - -## Usage - -### Initialization - -Use API key to create a new botimize object - -- import: - ```python - - from botimize import Botimize - - ``` - -- Facebook: - - ```python - - const botimize = botimize.Botimize(<'YOUR-API-KEY'>, 'facebook') - - ``` - -- Line: - - ```python - - const botimize = botimize.Botimize(<'YOUR-API-KEY'>, 'line') - - ``` -- Telegram: - - ```python - - const botimize = botimize.Botimize(<'YOUR-API-KEY'>, 'telegram') - - ``` -- Generic: - - ```python - - const botimize = botimize.Botimize(<'YOUR-API-KEY'>, 'generic') - - ``` - - -### Log incoming messages: - -- Facebook,Line,Telegram - - ```python - # message is the data your webhook received from Facebook,Line,Telegram platform - - botimize.log_incoming(message); - - ``` - -- Generic: - - ```python - 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: - -- Facebook,Line,Telegram,Generic - - ```python - outgoing_log = - { - "access_token": "PAGE_ACCESS_TOKEN", - "message": { - "text": "hellow, world!" - }, - "recipient": { - "id": "USER_ID" - } - } - botimize.log_outgoing(outgoing_log); - - ``` From 4ed5dd8bf57b2e6b54cb8d99b69cfbb8e2181396 Mon Sep 17 00:00:00 2001 From: kakalan123 Date: Fri, 23 Jun 2017 15:39:07 +0800 Subject: [PATCH 2/6] fix README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index d998687..bae1488 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Use Botimize API key to create a new botimize object, and `` should be `facebook`, `telegram`, `line` or `generic`. ```python - from botimize import Botimize + from botimize import Botimize ``` ```python const botimize = botimize.Botimize(, ) @@ -64,7 +64,6 @@ To log incoming message is very easy, just put the body received from platform w 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. #### Facebook -- For those who already use request to your poject: Put options of request into `logOutgoing()`. ```python outgoing_log = { 'recipient': { 'id': '1487766407960998' }, From 1dd5ef7565bd8d9646719974600582b18feadabd Mon Sep 17 00:00:00 2001 From: kakalan123 Date: Fri, 23 Jun 2017 15:44:39 +0800 Subject: [PATCH 3/6] fix README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bae1488..0e3d244 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ ## Table of contents -- [Setup](#Setup) -- [Usage](#Usage) -- [Initialization](#Initialization) +- [Setup](#setup) +- [Usage](#usage) +- [Initialization](#initialization) - [Log incoming messages](#log-incoming-messages) - [Log outgoing messages](#log-outgoing-messages) - [References & Full Examples](#references--full-examples) From 0d9cb67bf2b9a8dac38f4b7575f8bd9d31ec965e Mon Sep 17 00:00:00 2001 From: kakalan123 Date: Tue, 4 Jul 2017 12:53:31 +0800 Subject: [PATCH 4/6] fix bug --- botimize/botimize.py | 8 ++++---- examples/facebook_bot.py | 2 ++ examples/line_bot.py | 22 ++++++++++------------ setup.py | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/botimize/botimize.py b/botimize/botimize.py index 6add0ac..ecdd28e 100644 --- a/botimize/botimize.py +++ b/botimize/botimize.py @@ -1,13 +1,13 @@ import requests +supported_platform = ['facebook','line','telegram','generic'] + class Botimize: def __init__(self, apiKey, platform, api_url = 'https://api.botimize.io'): - self.apiKey = apiKey self.platform = platform - if(platform != 'facebook' and platform != 'line' and - platform != 'telegram' and platform != 'generic'): - print('unsupported platform:' + platform) + if platform not in supported_platform: + raise ValueError('unsupported platform:' + platform) self.apiUrl = api_url diff --git a/examples/facebook_bot.py b/examples/facebook_bot.py index 95c5cea..3d22155 100644 --- a/examples/facebook_bot.py +++ b/examples/facebook_bot.py @@ -26,6 +26,7 @@ def hello(): if request.method == 'POST': output = request.get_json() + #incoming botimize.log_incoming(output) for event in output['entry']: messaging = event['messaging'] @@ -35,6 +36,7 @@ def hello(): if x['message'].get('text'): message = x['message']['text'] bot.send_text_message(recipient_id, message) + #outgoing data = { "access_token":ACCESS_TOKEN, "message":x['message'], diff --git a/examples/line_bot.py b/examples/line_bot.py index 70b0c42..1286883 100644 --- a/examples/line_bot.py +++ b/examples/line_bot.py @@ -42,18 +42,16 @@ def callback(): @handler.add(MessageEvent, message=TextMessage) def handle_message(event): - - outgoingLog = { - 'receiver': { - 'id': 'Adam', - 'name': 'USER_SCREEN_NAME' - }, - 'content': { - 'type': 'text', - 'text': 'hello' - } - }; - botimize.log_outgoing(outgoingLog) + + outgoing_log = { + 'replyToken': event.reply_token, + 'messages': [{ + 'type': event.message.type, + 'text': event.message.text, + }], + 'channelAccessToken': channelAccessToken + } + botimize.log_outgoing(outgoing_log) line_bot_api.reply_message( event.reply_token, diff --git a/setup.py b/setup.py index df38689..901361c 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,12 @@ setup( name = 'botimize', packages = ['botimize'], - version = '1.2', + version = '1.3', description = 'Botimize python SDK', author = 'botimize', author_email = 'dev@botimize.io', url = 'https://github.com/botimize/botimize-sdk-python', - download_url = 'https://github.com/botimize/botimize-sdk-python/tarball/1.2', + download_url = 'https://github.com/botimize/botimize-sdk-python/tarball/1.3', keywords = ['botimize', 'python', 'sdk', 'chatbot', 'analytics'], classifiers = [], ) From 976041fc8bed96ca7c67857952a229ee5ed40347 Mon Sep 17 00:00:00 2001 From: kakalan123 Date: Tue, 4 Jul 2017 16:17:55 +0800 Subject: [PATCH 5/6] fix typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0e3d244..0c59fd0 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,10 @@ Use Botimize API key to create a new botimize object, and `` should be from botimize import Botimize ``` ```python - const botimize = botimize.Botimize(, ) + botimize = botimize.Botimize(, ) ``` ```python - const botimize = botimize.Botimize('NS1W0O5YCIDH9HJOGNQQWP5NU7YJ0S0S', 'facebook') + botimize = botimize.Botimize('NS1W0O5YCIDH9HJOGNQQWP5NU7YJ0S0S', 'facebook') ``` ### Log incoming messages: From a7e6fcce3394c9b53046c756c5b20e5527ef1da9 Mon Sep 17 00:00:00 2001 From: kakalan123 Date: Wed, 5 Jul 2017 16:14:06 +0800 Subject: [PATCH 6/6] update to 1.3 --- dist/botimize-1.3.tar.gz | Bin 0 -> 1033 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 dist/botimize-1.3.tar.gz diff --git a/dist/botimize-1.3.tar.gz b/dist/botimize-1.3.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..9f42eff853638d035b6489512565e8557f33e341 GIT binary patch literal 1033 zcmV+k1orzMiwFp&AzN7j|72-%bT49WbZKpAdSxv!E;BB4VR8WNSX+hcG{s_p;!&-k(Z@7o}5{QqeFuPdW$|Bd|bPp6;r|HPfn3jceq z@6CLWo7fW{{BIloKR8&DaiOrFf8|sviIB`Q-9n>f78AARBEgsVy|pGGU2(p%23E{c z3WcIE-3XFEbwg7sSZLiM6vjkK{Jc6p0m6WYuJLloQl^&63rXYk0F#W(>3)FgIf|BL zE@GI>+A5XFU_6GVQF9U*xB8_z4XtHVDuEGYrQ6wBeO+w?*t%)MDOZ@K_|)vfWEz4n zN%1=p=k!_#E-tJ*ZN@a(0t-KB{`Aqwa&HO)D^pRkIWgbB_JllP>89GCh$zysHx~>B zw$(hr);OV3k`0wsBS&(z1;M{NYqwy?j_$3Xy={%eKTVBiit$vQj#p#@gTdlm%I{KZ z(Cw}5t@SrP?TSTA&`?jHRn^uW>k{M+y0!72Sf8LWgY{8ZV0~Uk8JFs!qXV|8t285U zO68^Anr_FRlBbuI(M?CcHJ!>u+RQrA;urm{*Lbcr{Co7;mwfiWJl6GBZD&`{m%R0T zd97z~AO5dz>$C8`ZM(kaf5-9ciDx^S{~ZuF{C@_l1y6A8cU-*&YWhYdK7OkBmvDDx z-zMho6aSF+Rr#MYb7wQi{~!&pP5hrN{v#$;u2?KbAs5XpP@D!-{A#XFNuoL2s!vSu z6v#-p({Gs~M`(I(b=LH|LFi zyUhO&{O|a-Yxw^xc%M*3^b7tLwW4#lX0Z$DSH literal 0 HcmV?d00001