@electricface
2015-09-22T09:11:52.000000Z
字数 6993
阅读 2136
未分类
host: deepin.bearychat.com
获取 团队信息
返回
{"code" : 0,"result" : {"email_domain" : "linuxdeepin.com","inactive" : false,"created" : "2015-02-02T08:41:08.000+0800","updated" : "2015-07-02T09:00:37.000+0800","description" : "欢迎加入Deepin!","name" : "deepin","subdomain" : "deepin","id" : "=bw5Bi"}}
登陆接口
需要记录下 cookie
json args:
curl -H 'Content-Type:application/json' -X POST https://deepin.bearychat.com/api/signin -d '{"identity":"x","password":"x","remember_me":true}'|json_pp
返回
{"result" : {"tcp" : {"key" : "tcp:672bc028e0faa82414acf1ec4165368e","url" : "123.59.70.154:5222"},"tcp_path" : "123.59.70.154:5222","ws_host" : "wss://bearychat.com/nimbus/ws:6c41a0eeec0696ce94f7707f83d6a88d","user" : {"type" : "normal","name" : "鄂_开发_宋文泰","updated" : "2015-07-16T09:15:32.000+0800","full_name" : "宋文泰","team_id" : "=bw5Bi","email" : "songwentai@linuxdeepin.com","id" : "=bw8bU","authed" : ["weibo"],"avatars" : {"large" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/720/h/720","small" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/180/h/180","medium" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/360/h/360"},"role" : "normal","inactive" : false,"presence" : "online","created" : "2015-06-23T13:17:08.000+0800","preference" : {"guide_upload_file" : false,"guide_invite_member" : true,"sound" : true,"guide_add_robot" : true,"mention" : "half_hour","guide_new_channel" : true,"theme" : "default","guide_feedback" : true,"notification" : "all"},"profile" : "{\"position\":\"\\u57fa\\u7840\\u8bbe\\u65bd\\u5f00\\u53d1\",\"mobile\":\"18770030154\"}","avatar_url" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD"},"web_version" : "1c7475bb2ba5e3adf72ac81aeeeaa9a179faa8bb"},"code" : 0}
值得研究的地方
websocket
wss://bearychat.com/nimbus/ws:6c41a0eeec0696ce94f7707f83d6a88d
获取channel
请求头 Cookie: bearychat_517=???
也可以带上
bearychat=517;
Cookie: bearychat=517; bearychat_517=xxx;
curl -H 'Cookie: bearychat_517=xxx;' https://deepin.bearychat.com/api/channels|json_pp
返回数据
{"result" : [{"pinyins" : "deepin2015","inactive" : false,"created" : "2015-06-23T13:40:11.000+0800","latest_ts" : 1437708925808,"pinyin" : ["deepin2015"],"topic" : "Deepin 2015就靠我们啦!","name" : "Deepin2015","mention_count" : 0,"description" : null,"index_symbol" : "d","star_id" : null,"team_id" : "=bw5Bi","id" : "=bw6Q1","updated" : "2015-06-23T13:40:11.000+0800","read_ts" : 0,"member_count" : 31,"general" : false,"uid" : "=bw8ch","private" : false,"is_member" : false,"vchannel_id" : "=bw6Q1"},],"code" : 0}
获取归档频道
请求头 Cookie: bearychat_517=???
返回 同上 GET /api/channels
获取成员
请求头 Cookie: bearychat_517=???
参数
all=true 获取全部
返回
{"result" : [{"email" : "support@bearyinnovative.com","met_before" : true,"name" : "bearybot","unread_count" : 0,"full_name" : "BearyChat小助手","role" : "normal","read_ts" : 1435036747478,"pinyins" : "bearybot,bearychatxiaozhushou,bearychatxzs","hidden" : false,"type" : "assistant","presence" : "online","avatars" : {"large" : "https://dn-bearychat.qbox.me/robot_assistant.png?imageView2/1/w/720/h/720","medium" : "https://dn-bearychat.qbox.me/robot_assistant.png?imageView2/1/w/360/h/360","small" : "https://dn-bearychat.qbox.me/robot_assistant.png?imageView2/1/w/180/h/180"},"index_symbol" : "b","profile" : null,"team_id" : "=bw5Bi","inactive" : false,"pinyin" : ["bearybot","bearychatxiaozhushou","bearychatxzs"],"updated" : "2015-03-03T18:25:12.000+0800","created" : "2015-03-03T18:25:12.000+0800","conn" : "connected","avatar_url" : "https://dn-bearychat.qbox.me/robot_assistant.png","vchannel_id" : "=dvckN8O8","id" : "=bw6kX","latest_ts" : 1435036628537},
获取机器人
参数 all=true
获取某个频道下的消息
参数 limit=50
返回
{"uid" : "=bw8wJ","updated" : "2015-07-24T14:26:55.000+0800","team_id" : "=bw5Bi","robot_id" : null,"star_id" : null,"created" : "2015-07-24T14:26:55.000+0800","key" : "1437719215022.0000","subtype" : "normal","id" : "=b4BtH","refer_key" : null,"created_ts" : 1437719215022,"is_channel" : true,"vchannel_id" : "=bw5Iq","text" : "@<==bw8wS=> 这是LDAP和bugzilla集成时的问题,不用在这里问,我们只是暂时没管这个问题"}
获取当前登录用户信息
可获取 websocket 地址
返回
{"code" : 0,"result" : {"web_version" : "1c7475bb2ba5e3adf72ac81aeeeaa9a179faa8bb","user" : {"type" : "normal","team_id" : "=bw5Bi","authed" : ["weibo"],"preference" : {"guide_add_robot" : true,"guide_feedback" : true,"sound" : true,"mention" : "half_hour","guide_upload_file" : false,"notification" : "all","guide_new_channel" : true,"guide_invite_member" : true,"theme" : "default"},"created" : "2015-06-23T13:17:08.000+0800","id" : "=bw8bU","avatar_url" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD","role" : "normal","full_name" : "宋文泰","inactive" : false,"mobile" : "18770030154","name" : "鄂_开发_宋文泰","position" : "基础设施开发","email" : "songwentai@linuxdeepin.com","presence" : "online","avatars" : {"small" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/180/h/180","medium" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/360/h/360","large" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/720/h/720"},"updated" : "2015-07-16T09:15:32.000+0800"},"tcp" : {"key" : "tcp:1d1d8f68dfec225d239283719e434ad4","url" : "123.59.70.154:5222"},"ws_host" : "wss://bearychat.com/nimbus/ws:85455398e72618f8c5abcf3a3e47f543","tcp_path" : "123.59.70.154:5222"}}
websocket 消息:
就是 JSON 数据
{"uid":"=bw8bU","channel_id":"=bw6QP","type":"channel_typing"}
{"channel_id":"=bw6QP","vchannel_id":"=bw6QP","uid":"=bw8bU","text":"a","ts":1437727366103,"created_ts":1437727366103,"instance_no":0,"instance_seq":0,"key":"1437727366103.0000","type":"channel_message"}
180.150.189.101:443
ip.dst_host eq 180.150.189.101
type channel_message
{"id" : "=b4E9q","team_id" : "=bw5Bi","updated" : "2015-07-24T18:19:49.000+0800","uid" : null,"vchannel_id" : "=bw6Qz","key" : "1437733189649.0000","refer_key" : null,"created" : "2015-07-24T18:19:49.000+0800","text" : "[李鹤](https://tower.im/members/cedb0ec7f21a4ca8b7eb606db9ded8c2) 将任务 [用户中心-移动端适配](https://tower.im/projects/c774acec5c0d4749950d602881a07f68/todos/7ab1ed32eb7a41178f04f1eec826e621) 的截止时间设置为 15-07-27","is_channel" : true,"robot_id" : "=bw62L","ts" : 1437733189649,"created_ts" : 1437733189649,"type" : "channel_message","fallback" : "李鹤 将任务 用户中心-移动端适配 的截止时间设置为 15-07-27","subtype" : "robot"}
每次 call (带有 call_id 的 json 发送过去)
服务器都会回一个 reply
{"type":"reply","status":"ok","ts":1437810023683,"call_id":281,"code":0}
{"type":"reply","status":"ok","ts":1437810026728,"key":"1437810026728.0000","call_id":282,"code":0}
lib/BC
lib/BC/VChannel.pm
lib/BC/User.pm
lib/BC/Channel.pm
package BCBC::ENVBC::ENV::updateUsersInfoEC::ENV::updateChannelsInfoEC::ENV::getConnectionEC::ENV::getWebSocketTxping pongverify reply???callList{ id => callobj }call callid push to callListwhen get reply ok , callList remove it$BC::ENV::callIdsub call{my $ws = BC::ENV::getWebSocket;my $id = $BC::Caller::id;my ($data) = @_;$data->{call_id} = $id;_sendData($tx,$data);$BC::Caller::id++;}BC::User < BC::VChannelmy $u = BC::User->new(name => 'name');$c->sendMsg();msg hookBC::Channelmy $c = BC::Channel->new(name => 'name');$c->sendMsg();
beary chat 文本只支持 简单的 markdown
link
text
text
text
text
段落引用
@某个人
@<==bw5RQ=>
@<=$uid=>