Jam*_*ssy 1 facebook bots facebook-messenger
试图从我的机器人向用户发送位置?这是允许的吗?如果是,我的代码出了什么问题,我的JSON格式是正确的,我得到了
error: { message: '(#100) Unsupported attachment type',
type: 'OAuthException',
code: 100,
error_subcode: 2018046,
fbtrace_id: 'CObB3+0fgMw' }
Run Code Online (Sandbox Code Playgroud)
如果有人能够提供背景,那就太好了
function sendLocationMessage(sender,event){
let messageData={
attachment: {
"type": "location",
"payload": {
"coordinates":{
"lat": event.message.attachments[0].payload.coordinates.lat,
"long": event.message.attachments[0].payload.coordinates.long
} }
}
}
request({
url: 'https://graph.facebook.com/v2.6/me/messages',
qs: {access_token:token},
method: 'POST',
json: {
recipient: {id:sender},
message: messageData,
}
}, function(error, response, body) {
if (error) {
console.log('Error sending messages: ', error)
} else if (response.body.error) {
console.log('Error: ', response.body.error)
}
})
}
Run Code Online (Sandbox Code Playgroud)
不可以.Bot无法与附件类型共享其位置"type": "location",.错误消息清楚地调用它Unsupported attachment type.
相反,您可以执行的其中一个选项是,共享Google地图链接(静态).
messageData = {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [{
"title": 'Location Shared By Bot',
"subtitle": "Location Subtitle",
"image_url": https://maps.googleapis.com/maps/api/staticmap?key= + "YOUR_GMAPS_TOKEN" +
"&markers=color:red|label:B|" + lat + "," + long + "&size=360x360&zoom=13"
}]
}
}
参考:Messenger发送API参考 - https://developers.facebook.com/docs/messenger-platform/send-api-reference
谢谢,Sriram
| 归档时间: |
|
| 查看次数: |
3203 次 |
| 最近记录: |