Skip to content

Commit 3f3016d

Browse files
authored
Merge pull request #5 from kakalan123/master
update to 1.3
2 parents d6f6ebf + a7e6fcc commit 3f3016d

File tree

7 files changed

+147
-119
lines changed

7 files changed

+147
-119
lines changed

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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)

README.mdown

Lines changed: 0 additions & 101 deletions
This file was deleted.

botimize/botimize.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import requests
22

3+
supported_platform = ['facebook','line','telegram','generic']
4+
35
class Botimize:
46
def __init__(self, apiKey, platform, api_url = 'https://api.botimize.io'):
5-
67
self.apiKey = apiKey
78
self.platform = platform
8-
if(platform != 'facebook' and platform != 'line' and
9-
platform != 'telegram' and platform != 'generic'):
10-
print('unsupported platform:' + platform)
9+
if platform not in supported_platform:
10+
raise ValueError('unsupported platform:' + platform)
1111

1212
self.apiUrl = api_url
1313

dist/botimize-1.3.tar.gz

1.01 KB
Binary file not shown.

examples/facebook_bot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def hello():
2626

2727
if request.method == 'POST':
2828
output = request.get_json()
29+
#incoming
2930
botimize.log_incoming(output)
3031
for event in output['entry']:
3132
messaging = event['messaging']
@@ -35,6 +36,7 @@ def hello():
3536
if x['message'].get('text'):
3637
message = x['message']['text']
3738
bot.send_text_message(recipient_id, message)
39+
#outgoing
3840
data = {
3941
"access_token":ACCESS_TOKEN,
4042
"message":x['message'],

examples/line_bot.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,16 @@ def callback():
4242

4343
@handler.add(MessageEvent, message=TextMessage)
4444
def handle_message(event):
45-
46-
outgoingLog = {
47-
'receiver': {
48-
'id': 'Adam',
49-
'name': 'USER_SCREEN_NAME'
50-
},
51-
'content': {
52-
'type': 'text',
53-
'text': 'hello'
54-
}
55-
};
56-
botimize.log_outgoing(outgoingLog)
45+
46+
outgoing_log = {
47+
'replyToken': event.reply_token,
48+
'messages': [{
49+
'type': event.message.type,
50+
'text': event.message.text,
51+
}],
52+
'channelAccessToken': channelAccessToken
53+
}
54+
botimize.log_outgoing(outgoing_log)
5755

5856
line_bot_api.reply_message(
5957
event.reply_token,

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
setup(
33
name = 'botimize',
44
packages = ['botimize'],
5-
version = '1.2',
5+
version = '1.3',
66
description = 'Botimize python SDK',
77
author = 'botimize',
88
author_email = 'dev@botimize.io',
99
url = 'https://github.com/botimize/botimize-sdk-python',
10-
download_url = 'https://github.com/botimize/botimize-sdk-python/tarball/1.2',
10+
download_url = 'https://github.com/botimize/botimize-sdk-python/tarball/1.3',
1111
keywords = ['botimize', 'python', 'sdk', 'chatbot', 'analytics'],
1212
classifiers = [],
1313
)

0 commit comments

Comments
 (0)