尝试从我的机器人向用户发送位置?这是允许的吗?如果是,我的代码出了什么问题我的JSON格式是正确的,我得到了
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)
}
})
}
如果有人可以提供背景,那就太棒了
Error in .window.timeSeries(x, start, end, ...) :
.window.timeSeries is for time series and not for signal series.
In addition: There were 30 warnings (use warnings() to see them)
答案 0 :(得分:5)
没有。 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
谢谢, 斯利拉姆
答案 1 :(得分:1)
此外,如果要在单击卡时打开图像来添加某些功能,可以添加默认操作。在URL中,使用转义字符(%7C)调用api
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|YOUR_LATITUDE,YOUR_LONGITUDE&size=360x360&zoom=13",
"default_action": {
"type": "web_url",
"url": "https://maps.googleapis.com/maps/api/staticmap?key=YOUR_GMAPS_TOKEN&markers=color:red%7Clabel:A%7YOUR_LATITUDE,YOUR_LONGITUDE&size=360x360&zoom=13",
"messenger_extensions": true,
"webview_height_ratio": "tall"
}
}]
}
}