连接到Botsociety的客户端
项目描述
Botsociety Python客户端
连接到botsociety API,并提供易于使用的Python API
此实现受官方nodejs客户端的启发。
安装
pip install botsociety-client
使用示例
from botsociety import BotSocietyClient
client = BotSocietyClient(user_id="USER_ID",
api_key="API_KEY")
您可以在您的Botsociety个人资料页面找到USER_ID
和API_KEY
的值
auth()
测试与Botsociety的认证。
client.auth()
示例
In [4]: client.auth()
Out[4]:
{'auth': True,
'info': 'You are successfully calling the API. This is just a test API to check your authentication params.'}
conversations()
检索账户中的所有对话。
client.conversations()
示例
In [5]: client.conversations()
Out[5]:
[{'_id': '5af2c33e64aefa000b21b096',
'channel': 'facebook',
'createdAt': '2018-05-09T09:45:34.860Z',
'name': 'testbot mockup',
'questions': [],
'selected_model': 'iphone6',
'selected_variant': 'white',
'updatedAt': '2018-05-09T12:06:51.459Z'},
{'_id': '5af2e40964aefa000b21e108',
'channel': 'slack',
'createdAt': '2018-05-09T12:05:29.185Z',
'name': 'slack-test mockup',
'questions': [],
'selected_model': 'iphone6',
'selected_variant': 'white',
'updatedAt': '2018-05-09T12:05:31.593Z'}]
conversation('conversation_id')
检索单个对话的所有信息(例如,包括所有消息)。
client.conversation("5af2c33e64aefa000b21b096")
示例
In [6]: client.conversation("5af2c33e64aefa000b21b096")
Out[6]:
{'_id': '5af2c33e64aefa000b21b096',
'channel': 'facebook',
'createdAt': '2018-05-09T09:45:34.860Z',
'messages': [{'_belongs_to_socket_id': None,
'_conversation': '5af2c33e64aefa000b21b096',
'_id': '5af2c34164aefa000b21b097',
'_sender': '5af2c34164aefa000b21b09c',
'alternativeChoices': [],
'attachments': [{'choices': [], 'labels': [], 'size': 'horizontal'}],
'audio_duration': None,
'audio_url': None,
'audio_voice': None,
'choices': [],
'createdAt': '2018-05-09T09:45:37.195Z',
'intent': 'greet',
'is_next_message_linked': False,
'next_alternative': None,
'next_message': '5af2c34164aefa000b21b098',
'prev_alternative': None,
'prev_linked_messages': [],
'prev_message': None,
'progressiveId': 1,
'show_time': 1500,
'side': False,
'text': 'hello',
'text_with_variables': 'hello',
'type': 'text',
'updatedAt': '2018-05-09T09:49:34.469Z'}],
'name': 'testbot mockup',
'options': {'backgroundColor': '#FFFFFF',
'menu': [{'id': '0f13b412-1b61-337b-4486-3278bb657443',
'messages': [],
'nodes': [{'id': '6308000f-8a85-a546-adc8-a6cbc96c5fb3',
'messages': [],
'nodes': [],
'title': 'Contact us'}],
'title': 'Help'}],
'showKeyboard': True,
'showTypingIndicators': True},
'questions': [],
'rtl': False,
'selected_model': 'iphone6',
'selected_variant': 'white',
'set_welcome': False,
'updatedAt': '2018-05-09T12:06:51.459Z',
'ws_fans': '0',
'ws_page_category': '2301',
'ws_text': 'Hi, click the button below to start!'}
message('message_id', 'conversation_id')
检索关于会话中单个消息的所有信息。
client.message("5af2c34164aefa000b21b097", "5af2c33e64aefa000b21b096")
示例
In [7]: client.message("5af2c34164aefa000b21b097", "5af2c33e64aefa000b21b096")
Out[7]:
{'_belongs_to_socket_id': None,
'_conversation': '5af2c33e64aefa000b21b096',
'_id': '5af2c34164aefa000b21b097',
'_sender': '5af2c34164aefa000b21b09c',
'alternativeChoices': [],
'attachments': [{'choices': [], 'labels': [], 'size': 'horizontal'}],
'audio_duration': None,
'audio_url': None,
'audio_voice': None,
'choices': [],
'createdAt': '2018-05-09T09:45:37.195Z',
'intent': 'greet',
'is_next_message_linked': False,
'next_alternative': None,
'next_message': '5af2c34164aefa000b21b098',
'prev_alternative': None,
'prev_linked_messages': [],
'prev_message': None,
'progressiveId': 1,
'show_time': 1500,
'side': False,
'text': 'hello',
'text_with_variables': 'hello',
'type': 'text',
'updatedAt': '2018-05-09T09:49:34.469Z'}
变量('conversation_id')
检索会话的所有变量。
client.variables("5af2c33e64aefa000b21b096")
示例
In [8]: client.variables("5af2c33e64aefa000b21b096")
Out[8]: {'cuisine': {'values': ['chinese']}}
高级用法
指定自己的botsociety API服务器
如果您运行自己的botsociety API服务器,有一种方法可以指定其URL
from botsociety import BotSocietyClient
client = BotSocietyClient(user_id="USER_ID",
api_key="API_KEY",
api_url="http://yourapi.com")
更新日志
1.1.0 - 20.08.18
新增:
- 允许用户指定botsociety API的版本/URL
1.0.0 - 14.05.18
新增:
- 发布初始版本
- 功能与node js客户端库相匹配
许可
Apache许可证版本2.0下授权。版权所有2018 Rasa Technologies GmbH。 许可证副本。
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
botsociety-client-1.1.0.tar.gz (4.7 kB 查看哈希值)