bearyinnovative / OpenAPI

BearyChat 开放 API
https://openapi.bearychat.help/
39 stars 9 forks source link

使用 https://rtm.bearychat.com/message 接口推送消息返回没有权限 #11

Closed wutz closed 7 years ago

wutz commented 7 years ago

执行的命令请求

http POST https://rtm.bearychat.com/message \
    vchannel='=bwFlb'  \
    token= \
    text="this is a test"                                                                  

返回

HTTP/1.1 403 Forbidden
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Connection: keep-alive
Content-Length: 59
Content-Type: application/json;charset=utf-8
Date: Wed, 08 Mar 2017 04:16:23 GMT
Server: nginx/1.4.6 (Ubuntu)

{
    "code": 4,
    "error": "没有权限",
    "result": null
}
bcho commented 7 years ago

hi, 能确认一下这个 token 对应的 hubot 是否已经加入了对应的 vchannel 吗?现在是需要 hubot 加入了该 vchannel 才能往对应讨论组发送消息的。(FYI 这里的接口输出文案还在调整中,暂时可能会有些不明确)

wutz commented 7 years ago

vchannel 的信息:

http GET https://rtm.bearychat.com/v1/channel.info channel_id=='=bwFlb' token==                                                                             ~
HTTP/1.1 200 OK
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Connection: keep-alive
Content-Length: 461
Content-Type: application/json;charset=utf-8
Date: Wed, 08 Mar 2017 04:20:14 GMT
Server: nginx/1.4.6 (Ubuntu)

{
    "code": 0,
    "result": {
        "created": "2016-11-07T17:45:09.000+0800",
        "description": null,
        "general": false,
        "id": "=bwFlb",
        "inactive": false,
        "index_symbol": "t",
        "latest_ts": 1488942327182,
        "member_count": 4,
        "members": [
            {
                "uid": "=bw9dd"
            },
            {
                "uid": "=bwIHg"
            },
            {
                "uid": "=bwILs"
            },
            {
                "uid": "=bwNvJ"
            }
        ],
        "name": "test",
        "pinyin": [
            "test"
        ],
        "pinyins": "test",
        "private": true,
        "team_id": "=bw65H",
        "topic": null,
        "type": "normal",
        "uid": "=bw9dd",
        "updated": "2017-03-08T10:49:26.000+0800",
        "vchannel_id": "=bwFlb"
    }
}

hubot (test) 的信息:

http GET https://rtm.bearychat.com/v1/user.info user_id=='=bwNvJ' token==                                                                                   ~
HTTP/1.1 200 OK
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Connection: keep-alive
Content-Length: 1039
Content-Type: application/json;charset=utf-8
Date: Wed, 08 Mar 2017 04:49:04 GMT
Server: nginx/1.4.6 (Ubuntu)

{
    "code": 0,
    "result": {
        "avatar_url": "https://dn-bearychat.qbox.me/robot_hubot.png",
        "avatars": {
            "large": "https://dn-bearychat.qbox.me/robot_hubot.png?imageView2/1/w/720/h/720",
            "medium": "https://dn-bearychat.qbox.me/robot_hubot.png?imageView2/1/w/360/h/360",
            "small": "https://dn-bearychat.qbox.me/robot_hubot.png?imageView2/1/w/180/h/180"
        },
        "conn": "connected",
        "created": "2017-03-08T09:44:27.000+0800",
        "dnd": {
            "end": "07:00:00+0800",
            "manual_enabled": false,
            "schedule_enabled": false,
            "start": "22:00:00+0800"
        },
        "email": "hubot-@bearychat.com",
        "email_verified": false,
        "full_name": null,
        "hidden": true,
        "id": "=bwNvJ",
        "inactive": false,
        "index_symbol": "t",
        "latest_ts": 0,
        "met_before": true,
        "mobile": null,
        "mobile_verified": false,
        "name": "test",
        "owner_id": "=bw9dd",
        "pinyin": [
            "test"
        ],
        "pinyins": "test",
        "presence": "online",
        "read_ts": 0,
        "role": "normal",
        "team_id": "=bw65H",
        "token": "",
        "type": "hubot",
        "unread_count": 0,
        "updated": "2017-03-08T09:44:27.000+0800",
        "vchannel_id": "=bvQRb4Ch3"
    }
}

以上确认 hubot (test) 已经加入对应的 vchannel . 这个问题是今天才发生的,之前一直使用正常。

bcho commented 7 years ago

@wutaizeng 我先帮你把 issue 里面几个比较敏感的 token 信息编辑掉。

我们这边的请求日志里面看到的你这个 token 的几个请求都是 /message?token=xxx&vchannel=bwFlb

注意这里 vchannel 的数据在 url 的 query parameter 里面写少了一个 = (vchannel 的值是有 = 的,一般形式为 =bw52O

你可以试试在命令行中这样请求:

$ curl -XPOST https://rtm.bearychat.com/message -H"content-type: application/json" --data-binary '{"vchannel": "<vchannel_id>", "token": "<token>", "text": "test"}'

看看是否成功(把 <vchannel_id> / <token> 替换成对应值)

bcho commented 7 years ago

另外这个接口的请求文档可以先参考 https://github.com/bearyinnovative/OpenAPI/blob/master/rtm/api_message.md 这个草稿。

wutz commented 7 years ago

vchannel='=bwFlb' 确实有问题应该需要 \= 转义下,之前尝试过 curl 也是不能正常工作的。不过现在消息推送已经可以正常工作,非常感谢 @bcho 帮助!

bcho commented 7 years ago

不客气,如果有其他问题也欢迎发 issue 或者加入我们的 OpenAPI 反馈团队 http://openapi.beary.chat/join