Welcome to aiobearychat’s documentation!¶
BearyChat 异步 Python SDK
- Free software: MIT license
- Documentation: https://aiobearychat.readthedocs.org
- GitHub: https://github.com/mozillazg/aiobearychat
- PyPI: https://pypi.python.org/pypi/aiobearychat
- Python version: 3.5, 3.6
Features¶
- 封装所有的 OpenAPI
- 封装所有的 RTM HTTP API
- 支持不同的异步 HTTP 请求模块(aiohttp, tornado, ...)
Contents¶
aiobearychat¶
BearyChat 异步 Python SDK
- Free software: MIT license
- Documentation: https://aiobearychat.readthedocs.org
- GitHub: https://github.com/mozillazg/aiobearychat
- PyPI: https://pypi.python.org/pypi/aiobearychat
- Python version: 3.5, 3.6
Features¶
- 封装所有的 OpenAPI
- 封装所有的 RTM HTTP API
- 支持不同的异步 HTTP 请求模块(aiohttp, tornado, ...)
Usage¶
OpenAPI¶
import aiohttp
from aiobearychat.openapi.aiohttp import OpenAPI
async def main(token):
async with aiohttp.ClientSession() as session:
api = OpenAPI(session, token=token)
response = await api.user.list()
print(response.json())
RTM HTTP API¶
import aiohttp
from aiobearychat.rtm.aiohttp import RtmAPI
async def main(token):
async with aiohttp.ClientSession() as session:
api = RtmAPI(session, token=token)
response = await api.start()
pprint(response.json())
Credits¶
This package was created with Cookiecutter and the mozillazg/cookiecutter-pypackage project template.
Installation¶
At the command line:
$ pip install aiobearychat
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv aiobearychat
$ pip install aiobearychat
开放 API (OpenAPI) 服务¶
使用示例¶
import aiohttp
from aiobearychat.openapi.aiohttp import OpenAPI
async def main(token):
async with aiohttp.ClientSession() as session:
api = OpenAPI(session, token=token)
response = await api.user.list()
print(response.json())
上面的 aiobearychat.openapi.aiohttp.OpenAPI
是 aiobearychat.openapi.OpenAPI
的子类,表示使用
aiohttp
这个模块来进行 http 请求相关的操作。
具体 api 可以查看
aiobearychat.openapi.OpenAPI
的文档,同时也可以参考
官方文档 来理解
每个方法的含义。
RTM 服务 HTTP API¶
使用示例¶
import aiohttp
from aiobearychat.rtm.aiohttp import RtmAPI
async def main(token):
async with aiohttp.ClientSession() as session:
api = RtmAPI(session, token=token)
response = await api.start()
pprint(response.json())
上面的 aiobearychat.rtm.aiohttp.RtmAPI
是 aiobearychat.rtm.RtmAPI
的子类,表示使用
aiohttp
这个模块来进行 http 请求相关的操作。
具体 api 可以查看
aiobearychat.rtm.RtmAPI
的文档,同时也可以参考
官方文档 来理解
每个方法的含义。
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/mozillazg/aiobearychat/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
aiobearychat could always use more documentation, whether as part of the official aiobearychat docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/mozillazg/aiobearychat/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up aiobearychat for local development.
Fork the aiobearychat repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/aiobearychat.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv aiobearychat $ cd aiobearychat/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 aiobearychat tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 3.5 and 3.6. Check https://travis-ci.org/mozillazg/aiobearychat/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- mozillazg <mozillazg101@gmail.com>
Contributors¶
None yet. Why not be the first?
API Reference¶
aiobearychat.abc
¶
aiobearychat.requesters.aiohttp
¶
-
class
aiobearychat.requesters.aiohttp.
Requester
(session: aiohttp.client.ClientSession, *args: typing.Any, **kwargs: typing.Any) → None[源代码]¶
aiobearychat.sansio
¶
-
class
aiobearychat.sansio.
Response
(status, headers, body)[源代码]¶ 请求响应信息
-
body
= Attribute(name='body', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))¶
-
headers
= Attribute(name='headers', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))¶
-
status
= Attribute(name='status', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))¶ 状态码,比如 200
-
aiobearychat.openapi
¶
-
class
aiobearychat.openapi.
OpenAPI
(requester: aiobearychat.abc.Requester, token: str = NOTHING, *, base_url: str = '')[源代码]¶ 开放 API (OpenAPI) 服务.
参数: - requester (aiobearychat.abc.Requester) – 实际进行请求操作 requester
- token (str) – RTM token, 目前可以通过创建 hubot 机器人获得
- base_url (str) – 开放 API 的基地址
Members: Undoc-members: -
base_url
¶ 开放 API 的基地址。 默认是
https://api.bearychat.com/v1
-
meta
¶ meta 相关 API (是个
aiobearychat.openapi.meta_api.MetaAPI
实例).
-
team
¶ 团队相关 API (是个
aiobearychat.openapi.team_api.TeamAPI
实例).
-
user
¶ 用户相关 API (是个
aiobearychat.openapi.user_api.UserAPI
实例).
-
vchannel
¶ 聊天会话相关 API (是个
aiobearychat.openapi.vchannel_api.VchannelAPI
实例).
-
channel
¶ 讨论组相关 API (是个
aiobearychat.openapi.channel_api.ChannelAPI
实例).
-
session_channel
¶ 临时讨论组相关 API (是个
aiobearychat.openapi.session_channel_api.SessionChannelAPI
实例).
-
p2p
¶ P2P 会话相关 API (是个
aiobearychat.openapi.p2p_api.P2pAPI
实例).
-
message
¶ 消息相关 API (是个
aiobearychat.openapi.message_api.MessageAPI
实例).
-
emoji
¶ 团队自定义 emoji 相关 API (是个
aiobearychat.openapi.emoji_api.EmojiAPI
实例).
-
sticker
¶ 团队 sticker 相关 API (是个
aiobearychat.openapi.sticker_api.StickerAPI
实例).
-
rtm
¶ RTM 相关 API (是个
aiobearychat.openapi.rtm_api.RtmAPI
实例).
aiobearychat.openapi.aiohttp
¶
-
class
aiobearychat.openapi.aiohttp.
OpenAPI
(session: aiohttp.client.ClientSession, token: str = NOTHING, *, base_url: str = '')[源代码]¶ 使用 aiohttp 作为 OpenAPI 中相关 API 的 HTTP 请求模块
使用示例:
async def main(token): async with aiohttp.ClientSession() as session: api = OpenAPI(session, token=token) response = await api.user.list() print(response.json())
aiobearychat.openapi.channel_api
¶
讨论组相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.channel_api.
ChannelAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ 讨论组相关 API.
-
archive
(channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 归档一个讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.archive.md
参数: channel_id ( str
) – 讨论组 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "private": false, "general": true, "latest_ts": 1486367046281, "uid": "=bw52O", "name": "所有人", "is_member": false, "is_active": false, "type": "normal", "topic": null, "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
create
(name: str, *, topic: str = NOTHING, private: bool = NOTHING, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 创建一个讨论组.
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.create.md
param name: 讨论组名称,可以包含 2 到 20 个英文字符或 1 到 10 个中文字符。允许使用数字、下划线 (_
)、中线 (-
) 和点。 (示例:吃喝玩乐在深圳
) :type name:str
param topic: 讨论组话题 (示例: 今天吃什么?
)type topic: str
param private: 讨论组是否为私密? type private: bool
return: response. 一个 aiobearychat.sansio.Response
实例rtype: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 201 时: { "private": false, "general": true, "latest_ts": 1486367046281, "uid": "=bw52O", "name": "所有人", "is_member": false, "is_active": true, "type": "normal", "topic": null, "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
info
(channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回指定讨论组的完整信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.info.md
参数: channel_id ( str
) – 讨论组 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "private": false, "general": true, "latest_ts": 1486367046281, "uid": "=bw52O", "name": "所有人", "is_member": false, "is_active": true, "type": "normal", "topic": null, "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
invite
(channel_id: str, invite_uid: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 当前用户邀请一个团队成员加入讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.invite.md
参数: - channel_id (
str
) – 讨论组 id (示例:=bw52O
) - invite_uid (
str
) – 邀请用户 id (示例:=bw52O
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 204 时:
- channel_id (
-
join
(channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 当前用户加入指定讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.join.md
参数: channel_id ( str
) – 讨论组 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "private": false, "general": false, "latest_ts": 1486367046281, "uid": "=bw52O", "name": "吃喝玩乐在深圳", "is_member": false, "is_active": true, "type": "normal", "topic": null, "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
kick
(channel_id: str, kick_uid: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 当前用户移除一个讨论组成员。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.kick.md
参数: - channel_id (
str
) – 讨论组 id (示例:=bw52O
) - kick_uid (
str
) – 移除用户 id (示例:=bw52O
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 204 时:
- channel_id (
-
kickout
(channel_id: str, kick_uid: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 当前用户移除一个讨论组成员。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.kickout.md
参数: - channel_id (
str
) – 讨论组 id (示例:=bw52O
) - kick_uid (
str
) – 移除用户 id (示例:=bw52O
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 204 时:
- channel_id (
-
leave
(channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 当前用户离开讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.leave.md
参数: channel_id ( str
) – 讨论组 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 204 时:
-
list
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回团队内的讨论组列表,获取某个讨论组的完整信息,请使用
channel.info
.官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.list.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: [ { "private": false, "general": true, "latest_ts": 1486367046281, "uid": "=bw52O", "name": "所有人", "is_member": false, "is_active": true, "type": "normal", "topic": null, "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" } ]
-
unarchive
(channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 恢复一个已被归档的讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/channel.unarchive.md
参数: channel_id ( str
) – 讨论组 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "private": false, "general": true, "latest_ts": 1486367046281, "uid": "=bw52O", "name": "所有人", "is_member": false, "is_active": true, "type": "normal", "topic": null, "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
aiobearychat.openapi.emoji_api
¶
团队自定义 emoji 相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.emoji_api.
EmojiAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ 团队自定义 emoji 相关 API.
-
list
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回团队内的自定义 emoji 列表.
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/emoji.list.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: [ { "id": "=bw52O", "uid": "=bw52O", "team_id": "=bw52O", "name": "hello", "type": "emoji", "created": "2017-03-13T13:54:16.000+0000", "updated": "2017-03-13T13:54:16.000+0000", "url": "http://example.com/1.jpg" } ]
-
aiobearychat.openapi.message_api
¶
消息相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.message_api.
MessageAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ 消息相关 API.
-
create
(vchannel_id: str, text: str, attachments: list, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 发送一条消息到指定聊天会话。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/message.create.md
参数: - vchannel_id (
str
) – 指定的目标聊天会话 id (示例:=bw52O
) - text (
str
) – 消息内容 (示例:中午吃啥啊?
) - attachments (
list
) – 消息附件
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 201 时: { "key": "1485236262366.0193", "updated": "2017-01-24T13:37:42.000+0000", "is_channel": false, "uid": "=bw52O", "fallback": null, "attachments": [], "created": "2017-01-24T13:37:42.000+0000", "vchannel_id": "=bw52O", "refer_key": null, "robot_id": null, "created_ts": 1485236262366, "team_id": "=bw52O", "subtype": "normal", "text": "hello" }
- vchannel_id (
-
delete
(vchannel_id: str, message_key: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 删除一条消息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/message.delete.md
参数: - vchannel_id (
str
) – 消息聊天会话 id (示例:=bw52O
) - message_key (
str
) – 删除的消息 key (示例:1487667236785.0077
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 204 时:
- vchannel_id (
-
info
(vchannel_id: str, message_key: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回一条消息的信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/message.info.md
参数: - vchannel_id (
str
) – 指定的目标聊天会话 id (示例:=bw52O
) - message_key (
str
) – 获取消息的 key (示例:1487667236785.0077
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 200 时: { "key": "1485236262366.0193", "updated": "2017-01-24T13:37:42.000+0000", "is_channel": false, "uid": "=bw52O", "fallback": null, "attachments": [], "created": "2017-01-24T13:37:42.000+0000", "vchannel_id": "=bw52O", "refer_key": null, "robot_id": null, "created_ts": 1485236262366, "team_id": "=bw52O", "subtype": "normal", "text": "hello" }
- vchannel_id (
-
query
(vchannel_id: str, query: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 查询指定 vchannel 下的消息列表。支持以下几种查询算法:
查询 vchannel 下最新的消息,支持参数:
limit
: 查询数量限制,最大值为 100, 默认 20
从指定位置开始拉取若干条消息,支持参数:
key
: 开始位置的消息 key, 不可以和ts
同时使用ts
: 开始位置的消息 ts, 不可以和ts
同时使用forward
: 向前(时间发生方向)获取条数backward
: 向后(时间发生方向)获取条数
注意:
- 使用
key
查询时,查询区间不包括 key 对应的消息 - 使用
ts
查询时,查询区间包括 ts 对应的消息 forward
/backward
参数可以同时使用forward
/backward
参数最大值为 100,forward
/backward
均未指定时,默认使用forward=100
拉取一定时间窗口内的消息,支持参数:
from_key
/to_key
: 窗口区间的消息 keyfrom_ts
/to_ts
: 窗口区间的消息 tsforward
: 从 from 方向往 to 方向取的消息数backward
: 从 to 方向往 from 方向取的消息数
注意:
{from,to}_key
和{from,to}_ts
不可以混用使用
{from,to}_key
查询时,查询区间不包括 key 对应的消息使用
{from,to}_ts
查询时,查询区间包括 ts 对应的消息forward
和backward
参数只能选其中一个forward
/backward
均未指定时,默认使用forward=100
如果查询区间开始值比结束值大,返回空结果
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/message.query.md
param vchannel_id: 待查询 vchannel_id (示例: =bw52O
)type vchannel_id: str
param query: 消息查询 payload type query: str
return: response. 一个 aiobearychat.sansio.Response
实例rtype: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "messages": [ { "key": "1485236262366.0193", "updated": "2017-01-24T13:37:42.000+0000", "is_channel": false, "uid": "=bw52O", "fallback": null, "attachments": [], "created": "2017-01-24T13:37:42.000+0000", "vchannel_id": "=bw52O", "refer_key": null, "robot_id": null, "created_ts": 1485236262366, "team_id": "=bw52O", "subtype": "normal", "text": "hello" } ] }
-
update_text
(vchannel_id: str, message_key: str, text: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 更新一条消息的内容。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/message.update_text.md
参数: - vchannel_id (
str
) – 消息聊天会话 id (示例:=bw52O
) - message_key (
str
) – 更新的消息 key (示例:1487667236785.0077
) - text (
str
) – 更新的消息内容 (示例:中午吃啥啊?
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 200 时: { "key": "1485236262366.0193", "updated": "2017-01-24T13:37:42.000+0000", "is_channel": false, "uid": "=bw52O", "fallback": null, "attachments": [], "created": "2017-01-24T13:37:42.000+0000", "vchannel_id": "=bw52O", "refer_key": null, "robot_id": null, "created_ts": 1485236262366, "team_id": "=bw52O", "subtype": "normal", "text": "hello" }
- vchannel_id (
-
aiobearychat.openapi.meta_api
¶
meta 相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.meta_api.
MetaAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ meta 相关 API.
-
get
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回 BearyChat API 的状态。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/meta.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "version": "1" }
-
aiobearychat.openapi.p2p_api
¶
P2P 会话相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.p2p_api.
P2pAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ P2P 会话相关 API.
-
create
(user_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 创建一个 P2P 聊天会话。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/p2p.create.md
参数: user_id ( str
) – P2P 聊天另外一方的用户 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 201 时: { "id": "=bw52O", "team_id": "=bw52O", "vchannel_id": "=bw52O", "type": "p2p", "is_active": true, "is_member": true, "member_uids": [ "=bw52O", "=bw52P" ], "latest_ts": 1485238998284 }
-
info
(p2p_channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回一个 P2P 聊天会话的完整信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/p2p.info.md
参数: p2p_channel_id ( str
) – P2P 聊天会话 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "id": "=bw52O", "team_id": "=bw52O", "vchannel_id": "=bw52O", "type": "p2p", "is_active": true, "is_member": true, "member_uids": [ "=bw52O", "=bw52P" ], "latest_ts": 1485238998284 }
-
list
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回 P2P 聊天会话列表,获取某个 P2P 会话的完整信息,请使用
p2p.info
.官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/p2p.list.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: [ { "id": "=bw52O", "team_id": "=bw52O", "vchannel_id": "=bw52O", "type": "p2p", "is_active": true, "is_member": true, "member_uids": [ "=bw52O", "=bw52P" ], "latest_ts": 1485238998284 } ]
-
aiobearychat.openapi.rtm_api
¶
RTM 相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.rtm_api.
RtmAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ RTM 相关 API.
-
start
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 打开 RTM 连接会话.
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/rtm.start.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "ws_host": "wss://rtm.bearychat.com/nimbus/ws:xxx", "user": { "inactive": false, "role": "normal", "email": "support@bearyinnovative.com", "name": "BearyBot", "type": "assistant", "created": "2017-01-11T12:28:31.000+0000", "id": "=bwMkR", "avatars": { "small": null, "medium": null, "large": null }, "team_id": "=bw52O", "full_name": "倍洽小助手", "mobile": null, "profile": { "bio": null, "position": null, "skype": null } } }
-
aiobearychat.openapi.session_channel_api
¶
临时讨论组相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.session_channel_api.
SessionChannelAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ 临时讨论组相关 API.
-
archive
(session_channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 归档一个临时讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.archive.md
参数: session_channel_id ( str
) – 临时讨论组 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "latest_ts": "1489242467694", "name": "临时讨论组名称", "is_member": true, "is_active": false, "type": "session", "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
convert_to_channel
(session_channel_id: str, name: str, *, private: bool = True, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 将临时讨论组转换为讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.convert_to_channel.md
param session_channel_id: 临时讨论组 id (示例: =bw52O
)type session_channel_id: str
param name: 讨论组名称,可以包含 2 到 20 个英文字符或 1 到 10 个中文字符。允许使用数字、下划线 (_
)、中线 (-
) 和点。 (示例:吃喝玩乐在深圳
) :type name:str
param private: 讨论组是否为私密?默认值: True
type private: bool
return: response. 一个 aiobearychat.sansio.Response
实例rtype: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 201 时: { "latest_ts": "1489242467694", "name": "临时讨论组名称", "is_member": true, "is_active": false, "type": "session", "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
create
(member_uids: <function SessionChannelAPI.list at 0x7f23ba923a60>, *, name: str = NOTHING, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 创建一个临时讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.create.md
param name: 临时讨论组名称,可以包含 2 到 20 个英文字符或 1 到 10 个中文字符。允许使用数字、下划线 (_
)、中线 (-
) 和点。 (示例:吃喝玩乐在深圳
) :type name:str
param member_uids: 临时讨论组成员 id 列表 (示例: ["=bw52O", "=bw52P"]
)type member_uids: list
return: response. 一个 aiobearychat.sansio.Response
实例rtype: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 201 时: { "latest_ts": "1489242467694", "name": "临时讨论组名称", "is_member": true, "is_active": true, "type": "session", "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
info
(session_channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回一个临时讨论组的完整信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.info.md
参数: session_channel_id ( str
) – 讨论组 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "latest_ts": "1489242467694", "name": "临时讨论组名称", "is_member": true, "is_active": true, "type": "session", "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" }
-
invite
(session_channel_id: str, invite_uid: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 邀请一个团队成员加入临时讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.invite.md
参数: - session_channel_id (
str
) – 临时讨论组 id (示例:=bw52O
) - invite_uid (
str
) – 邀请用户 id (示例:=bw52O
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 204 时:
- session_channel_id (
-
kick
(session_channel_id: str, kick_uid: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 移除一个临时讨论组成员。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.kick.md
参数: - session_channel_id (
str
) – 临时讨论组 id (示例:=bw52O
) - kick_uid (
str
) – 邀请用户 id (示例:=bw52O
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 204 时:
- session_channel_id (
-
kickout
(session_channel_id: str, kick_uid: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 移除一个临时讨论组成员。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.kickout.md
参数: - session_channel_id (
str
) – 临时讨论组 id (示例:=bw52O
) - kick_uid (
str
) – 邀请用户 id (示例:=bw52O
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 204 时:
- session_channel_id (
-
leave
(session_channel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 离开临时讨论组。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.leave.md
参数: session_channel_id ( str
) – 临时讨论组 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 204 时:
-
list
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ - 返回团队内已经加入的临时讨论组列表,获取某个临时讨论组的完整信息,请使用
session_channel.info
.官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/session_channel.list.md
return: response. 一个 aiobearychat.sansio.Response
实例rtype: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: [ { "latest_ts": "1489242467694", "name": "临时讨论组名称", "is_member": true, "is_active": true, "type": "session", "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" } ]
-
aiobearychat.openapi.sticker_api
¶
团队 sticker 相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.sticker_api.
StickerAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ 团队 sticker 相关 API.
-
list
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回当前用户的自定义 sticker 列表.
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/sticker.list.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: [ { "pack": "黑白熊静态", "stickers": [ { "url": "https://dn-bearychat.qbox.me/sticker-gif-20.gif", "name": "累", "width": 240, "height": 240 } ] } ]
-
aiobearychat.openapi.team_api
¶
团队相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.team_api.
TeamAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ 团队相关 API.
-
info
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回当前团队信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/team.info.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "id": "=bw52O", "subdomain": "openapi", "name": "BearyChat OpenAPI", "email_domain": null, "logo_url": null, "description": "", "plan": "basic", "created": "2017-01-11T12:28:31.000+0000" }
-
aiobearychat.openapi.user_api
¶
用户相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.user_api.
UserAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ 用户相关 API.
-
info
(user_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回团队内指定用户完整信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/user.info.md
参数: user_id ( str
) – 指定用户 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "inactive": false, "role": "normal", "email": "support@bearyinnovative.com", "name": "BearyBot", "type": "assistant", "created": "2017-01-11T12:28:31.000+0000", "id": "=bwMkR", "avatars": { "small": null, "medium": null, "large": null }, "team_id": "=bw52O", "full_name": "倍洽小助手", "mobile": null, "profile": { "bio": null, "position": null, "skype": null } }
-
list
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回团队内的用户列表,获取某个用户的完整信息,请使用
user.info
.官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/user.list.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: [ { "inactive": false, "role": "normal", "email": "support@bearyinnovative.com", "name": "BearyBot", "type": "assistant", "created": "2017-01-11T12:28:31.000+0000", "id": "=bwMkR", "avatars": { "small": null, "medium": null, "large": null }, "team_id": "=bw52O", "full_name": "倍洽小助手", "mobile": null, "profile": { "bio": null, "position": null, "skype": null } } ]
-
me
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回当前用户的信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/user.me.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "inactive": false, "role": "normal", "email": "support@bearyinnovative.com", "name": "BearyBot", "type": "assistant", "created": "2017-01-11T12:28:31.000+0000", "id": "=bwMkR", "avatars": { "small": null, "medium": null, "large": null }, "team_id": "=bw52O", "full_name": "倍洽小助手", "mobile": null, "profile": { "bio": null, "position": null, "skype": null } }
-
update_me
(*, name: str = NOTHING, full_name: str = NOTHING, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 更新当前用户信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/user.update_me.md
参数: - name (
str
) – 用户名 (@name) (示例:beary_bot
) - full_name (
str
) – 用户全名 (示例:BearyBot
)
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 200 时: { "inactive": false, "role": "normal", "email": "support@bearyinnovative.com", "name": "BearyBot", "type": "assistant", "created": "2017-01-11T12:28:31.000+0000", "id": "=bwMkR", "avatars": { "small": null, "medium": null, "large": null }, "team_id": "=bw52O", "full_name": "倍洽小助手", "mobile": null, "profile": { "bio": null, "position": null, "skype": null } }
- name (
-
aiobearychat.openapi.vchannel_api
¶
聊天会话相关 API.
auto generated by script at 2017-08-24 21:50:13.459796. don’t edit it.
-
class
aiobearychat.openapi.vchannel_api.
VchannelAPI
(requester: aiobearychat.abc.Requester, token: str, *, base_url: str, **kwargs)[源代码]¶ 聊天会话相关 API.
-
info
(vchannel_id: str, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 返回指定聊天会话的完整信息。
官方文档地址:https://github.com/bearyinnovative/OpenAPI/blob/master/api/vchannel.info.md
参数: vchannel_id ( str
) – 聊天会话 id (示例:=bw52O
)返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: // Channel { "private": false, "general": true, "latest_ts": 1486367046281, "uid": "=bw52O", "name": "所有人", "is_member": false, "is_active": true, "type": "normal", "topic": null, "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" } // SessionChannel { "latest_ts": "1489242467694", "name": "临时讨论组名称", "is_member": true, "is_active": true, "type": "session", "member_uids": [ "=bw52O" ], "vchannel_id": "=bw52O", "id": "=bw52O", "team_id": "=bw52O" } // P2PChannel { "id": "=bw52O", "team_id": "=bw52O", "vchannel_id": "=bw52O", "type": "p2p", "is_active": true, "is_member": true, "member_uids": [ "=bw52O", "=bw52P" ], "latest_ts": 1485238998284 }
-
aiobearychat.rtm
¶
-
class
aiobearychat.rtm.
RtmAPI
(requester: aiobearychat.abc.Requester, token: str = NOTHING, *, base_url: str = '')[源代码]¶ RTM HTTP 相关 API.
参数: - requester (aiobearychat.abc.Requester) – 实际进行请求操作的 requester
- token (str) – RTM token, 目前可以通过创建 hubot 机器人获得
- base_url (str) – RTM HTTP API
-
base_url
= 'https://rtm.bearychat.com'¶ RTM HTTP API 的基地址
-
message
(vchannel: str, text: str, *, markdown: bool = True, attachments: typing.Union[list, NoneType] = None, **requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 发送富文本消息
官方文档地址: https://github.com/bearyinnovative/OpenAPI/blob/master/rtm/api_message.md
参数: - vchannel (str) – 目标会话 id,示例:
=bw52O
- text (str) – 消息正文
- markdown (bool) – 消息正文是否使用 markdown 格式?(默认值:
True
) - attachments (
list
) –消息 attachment 结构,示例:
[ { "title": "test_title", # attachment 标题,title / text 至少包含一个 "text": "test_text", # attachment 内容,title / text 至少包含一个 "images": [{ # attachment 图片列表,可选 "url": "http://example.com/1.jpg" }], "color": "#cb3f20" # attachment 颜色,可选 } ]
返回: response. 一个
aiobearychat.sansio.Response
实例返回类型: response.body
返回值示例:response.status 等于 200 时: { "code": 0, "result": null }
- vchannel (str) – 目标会话 id,示例:
-
start
(**requester_params: typing.Any) → aiobearychat.sansio.Response[源代码]¶ 获取 RTM 模式的连接地址和用户信息。
官方文档地址: https://github.com/bearyinnovative/OpenAPI/blob/master/rtm/api_start.md
返回: response. 一个 aiobearychat.sansio.Response
实例返回类型: aiobearychat.sansio.Response
response.body
返回值示例:response.status 等于 200 时: { "code": 0, "result": { // RTM token 对应用户结构 "user": {}, // RTM 连接地址 5 分钟内有效 "ws_host": "wss://rtm.bearychat.com/nimbus/ws:xxx" } }
aiobearychat.rtm.aiohttp
¶
-
class
aiobearychat.rtm.aiohttp.
RtmAPI
(session: aiohttp.client.ClientSession, token: str = NOTHING, *, base_url: str = '')[源代码]¶ 使用 aiohttp 作为 RtmAPI 中相关 API 的 HTTP 请求模块
使用示例:
async def main(token): async with aiohttp.ClientSession() as session: api = RtmAPI(session, token=token) response = await api.start() print(response.json())