rocket.chat python api wrapper示例
阅读原文
建议阅读原文,始终查看最新文档版本,获得最佳阅读体验:《rocket.chat python api wrapper示例》
rocket.chat详细介绍
请看此文:《rocket.chat–开源的跨平台即时通讯软件》
rocket.chat HTTP API示例
官方网站
jadolg/rocketchat_API: Python API wrapper for Rocket.Chat
安装库
pip3 install rocketchat_API
#注意rocketchat_API依赖requests
最简单的示例–获取当前授权用户的基本信息
from pprint import pprint
from rocketchat_API.rocketchat import RocketChat
rocket = RocketChat(user_id='<此处替换为你的user id>', auth_token='<此处替换为你的auth token>', server_url='http://10.65.37.237:3000')
pprint(rocket.me().json())
输出
发送消息给channel
pprint(rocket.chat_post_message('good news everyone!', channel='GENERAL', alias='Farnsworth').json())
相应的channel确实出现了刚刚用api发送的消息
发送消息给room或者某个用户
#注意:The room ID or an array of room IDs where the message is to be sent. You can use channel name or username. The channel name must have the # prefix. @ refers to username.
pprint(rocket.chat_post_message('wow!', room_id='@bob', alias='API-user').json())