Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# [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 `<PLATFORM>` should be `facebook`, `telegram`, `line` or `generic`.

```python
from botimize import Botimize
```
```python
botimize = botimize.Botimize(<YOUR-API-KEY>, <PLATFORM>)
```
```python
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
```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)
101 changes: 0 additions & 101 deletions README.mdown

This file was deleted.

8 changes: 4 additions & 4 deletions botimize/botimize.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Binary file added dist/botimize-1.3.tar.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/facebook_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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'],
Expand Down
22 changes: 10 additions & 12 deletions examples/line_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [],
)