如何从 Facebook Messenger 平台发送位置信息?
How to send location from Facebook messenger platform?
有一种方法可以从移动客户端将我的位置发送到 facebook-messenger,但我如何才能从机器人发送一些位置? (信使平台api)
当我尝试从机器人发送类似的结构时,出现错误:
(#100) Unsupported attachment type
有没有办法从机器人发送我的位置?
收到的机器人消息示例:
{
"object": "page",
"entry": [{
"id": "1719442148306048",
"time": 1466780344978,
"messaging": [{
"sender": {"id": "123456789"},
"recipient": {"id": "987654321"},
"timestamp": 1466780344847,
"message": {
"mid": "mid.12345698875:c80066d69b6cee1779",
"seq": 65,
"attachments": [{
"title": "Dmitry's Location",
"url": "Link to bing.com through facebook redirect"
"type": "location",
"payload": {"coordinates": {"lat": 55, "long": 37}}
}]
}
}]
}]
}
我尝试像这样发送带有附件的消息:
"attachment": {
"type": "location",
"payload": {"coordinates": {"lat": 55, "long": 37}}
}
有解决方法。
我们可以将带有静态地图图像和 url 的通用模板发送到动态。
对于 iOS 本机地图应用程序,我们可以使用地址 http://maps.apple.com/maps(它将所有非 iOS 用户重定向到具有相同参数的 Google 地图)。在 Android 它打开 Google 地图应用。
{
"recipient": {"id": "132456"},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": {
"element": {
"title": "Your current location",
"image_url": "https:\/\/maps.googleapis.com\/maps\/api\/staticmap?size=764x400¢er="+lat+","+long+"&zoom=25&markers="+lat+","+long,
"item_url": "http:\/\/maps.apple.com\/maps?q="+lat+","+long+"&z=16"
}
}
}
}
}
}
Dmitry,感谢您的破解! FB API 略有变化,有效载荷部分对我有用:
payload = dict()
payload['type'] = 'template'
payload['text'] = dict(
template_type="generic",
elements=[
dict(
title='{venue} location',
# subtitle='Test',
image_url="https://maps.googleapis.com/maps/api/staticmap?size=764x400¢er=" + lat + "," + long +
"&zoom=15&markers=" + lat + "," + long,
default_action=dict(
type="web_url",
url="http://maps.apple.com/maps?q=" + venue + "&ll=" + lat + "," + long +
"&z=15"
)
) # buttons=[])
]
)
有一种方法可以从移动客户端将我的位置发送到 facebook-messenger,但我如何才能从机器人发送一些位置? (信使平台api)
当我尝试从机器人发送类似的结构时,出现错误:
(#100) Unsupported attachment type
有没有办法从机器人发送我的位置?
收到的机器人消息示例:
{
"object": "page",
"entry": [{
"id": "1719442148306048",
"time": 1466780344978,
"messaging": [{
"sender": {"id": "123456789"},
"recipient": {"id": "987654321"},
"timestamp": 1466780344847,
"message": {
"mid": "mid.12345698875:c80066d69b6cee1779",
"seq": 65,
"attachments": [{
"title": "Dmitry's Location",
"url": "Link to bing.com through facebook redirect"
"type": "location",
"payload": {"coordinates": {"lat": 55, "long": 37}}
}]
}
}]
}]
}
我尝试像这样发送带有附件的消息:
"attachment": {
"type": "location",
"payload": {"coordinates": {"lat": 55, "long": 37}}
}
有解决方法。 我们可以将带有静态地图图像和 url 的通用模板发送到动态。 对于 iOS 本机地图应用程序,我们可以使用地址 http://maps.apple.com/maps(它将所有非 iOS 用户重定向到具有相同参数的 Google 地图)。在 Android 它打开 Google 地图应用。
{
"recipient": {"id": "132456"},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": {
"element": {
"title": "Your current location",
"image_url": "https:\/\/maps.googleapis.com\/maps\/api\/staticmap?size=764x400¢er="+lat+","+long+"&zoom=25&markers="+lat+","+long,
"item_url": "http:\/\/maps.apple.com\/maps?q="+lat+","+long+"&z=16"
}
}
}
}
}
}
Dmitry,感谢您的破解! FB API 略有变化,有效载荷部分对我有用:
payload = dict()
payload['type'] = 'template'
payload['text'] = dict(
template_type="generic",
elements=[
dict(
title='{venue} location',
# subtitle='Test',
image_url="https://maps.googleapis.com/maps/api/staticmap?size=764x400¢er=" + lat + "," + long +
"&zoom=15&markers=" + lat + "," + long,
default_action=dict(
type="web_url",
url="http://maps.apple.com/maps?q=" + venue + "&ll=" + lat + "," + long +
"&z=15"
)
) # buttons=[])
]
)