在向机器人发送活动的步骤中根据此处的文档,
https://docs.botframework.com/en-us/restapi/directline3/#navtitle
我应该将此作为发布请求的正文内容传递
{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello"
}
我正在使用以下参数在 python 中发出 POST 请求,但它不起作用。
msg = {"type": "message","channelId": "directline","conversation":{"id": str(convId)},"from":{"id": "test_user1"},"text": "hello"}
header = {"Authorization":"Bearer q1-Tr4sRrAI.cwA.BmE.n7xMxGl-QLoT7qvJ-tNIcwAd69V-KOn5see6ki5tmOM", "Content-Type":"application/json", "Content-Length": "512"}
send2 = "https://directline.botframework.com/v3/directline/conversations/"+str(convId)+"/activities"
rsa1 = requests.post(send2,data=msg, headers=header)
这给了我这个错误:
{
"error": {
"code": "MissingProperty",
"message": "Invalid or missing activities in HTTP body"
}
}
在此步骤之前,一切正常。
编辑1:即使我添加了在代码中更新的内容长度,它也会给出相同的错误
编辑2:如果我将味精更改为 json.dumps(msg)
rsa1 = requests.post(send2,data=json.dumps(msg), headers=header)
我得到回应:
{u'error': {u'message': u'Failed to send activity: bot returned an error', u'code': u'ServiceError'}}
{
"error": {
"code": "ServiceError",
"message": "Failed to send activity: bot returned an error"
}
}
直线 API 只是不工作,在 Skype 客户端上一切正常。