[关闭]
@electricface 2015-09-22T09:11:52.000000Z 字数 6993 阅读 1970

bearychat.com 机器人账号研究

未分类


host: deepin.bearychat.com

GET /api/team

获取 团队信息
返回

  1. {
  2. "code" : 0,
  3. "result" : {
  4. "email_domain" : "linuxdeepin.com",
  5. "inactive" : false,
  6. "created" : "2015-02-02T08:41:08.000+0800",
  7. "updated" : "2015-07-02T09:00:37.000+0800",
  8. "description" : "欢迎加入Deepin!",
  9. "name" : "deepin",
  10. "subdomain" : "deepin",
  11. "id" : "=bw5Bi"
  12. }
  13. }

POST /api/signin

登陆接口
需要记录下 cookie
json args:

  1. curl -H 'Content-Type:application/json' -X POST https://deepin.bearychat.com/api/signin -d '{"identity":"x","password":"x","remember_me":true}'|json_pp

返回

  1. {
  2. "result" : {
  3. "tcp" : {
  4. "key" : "tcp:672bc028e0faa82414acf1ec4165368e",
  5. "url" : "123.59.70.154:5222"
  6. },
  7. "tcp_path" : "123.59.70.154:5222",
  8. "ws_host" : "wss://bearychat.com/nimbus/ws:6c41a0eeec0696ce94f7707f83d6a88d",
  9. "user" : {
  10. "type" : "normal",
  11. "name" : "鄂_开发_宋文泰",
  12. "updated" : "2015-07-16T09:15:32.000+0800",
  13. "full_name" : "宋文泰",
  14. "team_id" : "=bw5Bi",
  15. "email" : "songwentai@linuxdeepin.com",
  16. "id" : "=bw8bU",
  17. "authed" : [
  18. "weibo"
  19. ],
  20. "avatars" : {
  21. "large" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/720/h/720",
  22. "small" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/180/h/180",
  23. "medium" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/360/h/360"
  24. },
  25. "role" : "normal",
  26. "inactive" : false,
  27. "presence" : "online",
  28. "created" : "2015-06-23T13:17:08.000+0800",
  29. "preference" : {
  30. "guide_upload_file" : false,
  31. "guide_invite_member" : true,
  32. "sound" : true,
  33. "guide_add_robot" : true,
  34. "mention" : "half_hour",
  35. "guide_new_channel" : true,
  36. "theme" : "default",
  37. "guide_feedback" : true,
  38. "notification" : "all"
  39. },
  40. "profile" : "{\"position\":\"\\u57fa\\u7840\\u8bbe\\u65bd\\u5f00\\u53d1\",\"mobile\":\"18770030154\"}",
  41. "avatar_url" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD"
  42. },
  43. "web_version" : "1c7475bb2ba5e3adf72ac81aeeeaa9a179faa8bb"
  44. },
  45. "code" : 0
  46. }

值得研究的地方
websocket
wss://bearychat.com/nimbus/ws:6c41a0eeec0696ce94f7707f83d6a88d

获取channel

GET /api/channels

请求头 Cookie: bearychat_517=???
也可以带上
bearychat=517;
Cookie: bearychat=517; bearychat_517=xxx;

  1. curl -H 'Cookie: bearychat_517=xxx;' https://deepin.bearychat.com/api/channels|json_pp

返回数据

  1. {
  2. "result" : [
  3. {
  4. "pinyins" : "deepin2015",
  5. "inactive" : false,
  6. "created" : "2015-06-23T13:40:11.000+0800",
  7. "latest_ts" : 1437708925808,
  8. "pinyin" : [
  9. "deepin2015"
  10. ],
  11. "topic" : "Deepin 2015就靠我们啦!",
  12. "name" : "Deepin2015",
  13. "mention_count" : 0,
  14. "description" : null,
  15. "index_symbol" : "d",
  16. "star_id" : null,
  17. "team_id" : "=bw5Bi",
  18. "id" : "=bw6Q1",
  19. "updated" : "2015-06-23T13:40:11.000+0800",
  20. "read_ts" : 0,
  21. "member_count" : 31,
  22. "general" : false,
  23. "uid" : "=bw8ch",
  24. "private" : false,
  25. "is_member" : false,
  26. "vchannel_id" : "=bw6Q1"
  27. },
  28. ],
  29. "code" : 0
  30. }

GET /api/channels/archived

获取归档频道
请求头 Cookie: bearychat_517=???
返回 同上 GET /api/channels

GET /api/members

获取成员
请求头 Cookie: bearychat_517=???
参数
all=true 获取全部

返回

  1. {
  2. "result" : [
  3. {
  4. "email" : "support@bearyinnovative.com",
  5. "met_before" : true,
  6. "name" : "bearybot",
  7. "unread_count" : 0,
  8. "full_name" : "BearyChat小助手",
  9. "role" : "normal",
  10. "read_ts" : 1435036747478,
  11. "pinyins" : "bearybot,bearychatxiaozhushou,bearychatxzs",
  12. "hidden" : false,
  13. "type" : "assistant",
  14. "presence" : "online",
  15. "avatars" : {
  16. "large" : "https://dn-bearychat.qbox.me/robot_assistant.png?imageView2/1/w/720/h/720",
  17. "medium" : "https://dn-bearychat.qbox.me/robot_assistant.png?imageView2/1/w/360/h/360",
  18. "small" : "https://dn-bearychat.qbox.me/robot_assistant.png?imageView2/1/w/180/h/180"
  19. },
  20. "index_symbol" : "b",
  21. "profile" : null,
  22. "team_id" : "=bw5Bi",
  23. "inactive" : false,
  24. "pinyin" : [
  25. "bearybot",
  26. "bearychatxiaozhushou",
  27. "bearychatxzs"
  28. ],
  29. "updated" : "2015-03-03T18:25:12.000+0800",
  30. "created" : "2015-03-03T18:25:12.000+0800",
  31. "conn" : "connected",
  32. "avatar_url" : "https://dn-bearychat.qbox.me/robot_assistant.png",
  33. "vchannel_id" : "=dvckN8O8",
  34. "id" : "=bw6kX",
  35. "latest_ts" : 1435036628537
  36. },

GET api/robots

获取机器人
参数 all=true

GET /api/vchannels/:channelId/messages

获取某个频道下的消息
参数 limit=50
返回

  1. {
  2. "uid" : "=bw8wJ",
  3. "updated" : "2015-07-24T14:26:55.000+0800",
  4. "team_id" : "=bw5Bi",
  5. "robot_id" : null,
  6. "star_id" : null,
  7. "created" : "2015-07-24T14:26:55.000+0800",
  8. "key" : "1437719215022.0000",
  9. "subtype" : "normal",
  10. "id" : "=b4BtH",
  11. "refer_key" : null,
  12. "created_ts" : 1437719215022,
  13. "is_channel" : true,
  14. "vchannel_id" : "=bw5Iq",
  15. "text" : "@<==bw8wS=> 这是LDAP和bugzilla集成时的问题,不用在这里问,我们只是暂时没管这个问题"
  16. }

GET /api/current_user

获取当前登录用户信息
可获取 websocket 地址

返回

  1. {
  2. "code" : 0,
  3. "result" : {
  4. "web_version" : "1c7475bb2ba5e3adf72ac81aeeeaa9a179faa8bb",
  5. "user" : {
  6. "type" : "normal",
  7. "team_id" : "=bw5Bi",
  8. "authed" : [
  9. "weibo"
  10. ],
  11. "preference" : {
  12. "guide_add_robot" : true,
  13. "guide_feedback" : true,
  14. "sound" : true,
  15. "mention" : "half_hour",
  16. "guide_upload_file" : false,
  17. "notification" : "all",
  18. "guide_new_channel" : true,
  19. "guide_invite_member" : true,
  20. "theme" : "default"
  21. },
  22. "created" : "2015-06-23T13:17:08.000+0800",
  23. "id" : "=bw8bU",
  24. "avatar_url" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD",
  25. "role" : "normal",
  26. "full_name" : "宋文泰",
  27. "inactive" : false,
  28. "mobile" : "18770030154",
  29. "name" : "鄂_开发_宋文泰",
  30. "position" : "基础设施开发",
  31. "email" : "songwentai@linuxdeepin.com",
  32. "presence" : "online",
  33. "avatars" : {
  34. "small" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/180/h/180",
  35. "medium" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/360/h/360",
  36. "large" : "https://dn-bearychat.qbox.me/FgMbBbr7mIfwLJoPh38sHQRFCwyD?imageView2/1/w/720/h/720"
  37. },
  38. "updated" : "2015-07-16T09:15:32.000+0800"
  39. },
  40. "tcp" : {
  41. "key" : "tcp:1d1d8f68dfec225d239283719e434ad4",
  42. "url" : "123.59.70.154:5222"
  43. },
  44. "ws_host" : "wss://bearychat.com/nimbus/ws:85455398e72618f8c5abcf3a3e47f543",
  45. "tcp_path" : "123.59.70.154:5222"
  46. }
  47. }

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

  1. {
  2. "id" : "=b4E9q",
  3. "team_id" : "=bw5Bi",
  4. "updated" : "2015-07-24T18:19:49.000+0800",
  5. "uid" : null,
  6. "vchannel_id" : "=bw6Qz",
  7. "key" : "1437733189649.0000",
  8. "refer_key" : null,
  9. "created" : "2015-07-24T18:19:49.000+0800",
  10. "text" : "[李鹤](https://tower.im/members/cedb0ec7f21a4ca8b7eb606db9ded8c2) 将任务 [用户中心-移动端适配](https://tower.im/projects/c774acec5c0d4749950d602881a07f68/todos/7ab1ed32eb7a41178f04f1eec826e621) 的截止时间设置为 15-07-27",
  11. "is_channel" : true,
  12. "robot_id" : "=bw62L",
  13. "ts" : 1437733189649,
  14. "created_ts" : 1437733189649,
  15. "type" : "channel_message",
  16. "fallback" : "李鹤 将任务 用户中心-移动端适配 的截止时间设置为 15-07-27",
  17. "subtype" : "robot"
  18. }

每次 call (带有 call_id 的 json 发送过去)
服务器都会回一个 reply

ping 's reply

{"type":"reply","status":"ok","ts":1437810023683,"call_id":281,"code":0}

send channal message 's reply

{"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

  1. package BC
  2. BC::ENV
  3. BC::ENV::updateUsersInfo
  4. EC::ENV::updateChannelsInfo
  5. EC::ENV::getConnection
  6. EC::ENV::getWebSocketTx
  7. ping pong
  8. verify reply???
  9. callList
  10. { id => callobj }
  11. call callid push to callList
  12. when get reply ok , callList remove it
  13. $BC::ENV::callId
  14. sub call
  15. {
  16. my $ws = BC::ENV::getWebSocket;
  17. my $id = $BC::Caller::id;
  18. my ($data) = @_;
  19. $data->{call_id} = $id;
  20. _sendData($tx,$data);
  21. $BC::Caller::id++;
  22. }
  23. BC::User < BC::VChannel
  24. my $u = BC::User->new(name => 'name');
  25. $c->sendMsg();
  26. msg hook
  27. BC::Channel
  28. my $c = BC::Channel->new(name => 'name');
  29. $c->sendMsg();

beary chat 文本只支持 简单的 markdown
link
text
text
text
text

段落引用

@某个人
@<==bw5RQ=>
@<=$uid=>

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注