2016-11-20 93 views
3

我正在创建一个FB信使聊天机器人。发送图像URL链接时通过哪种JSON格式,会生成预览。Facebook messenger chatbot url preview

On the above screenshot, you can see that if I manually send a URL, FB messenger will generate the preview. Similarly if the chatbot sends an URL the messenger has to generate the preview. So my query is what is the JSON formate which will even generate the preview if I send an URL?

在上面的截图,你可以看到,如果我手动发送URL,FB Messenger将生成预览。同样,如果聊天机器人发送一个URL,信使必须产生预览。所以我的查询是什么JSON甲酸盐甚至会生成预览,如果我发送一个URL?

注:我不想发送图像作为一个附件,因为有尺寸限制

+0

你到底需要什么? –

+0

你有没有办法做到这一点? –

+0

@UriAbramson还没有。 –

回答

0

你将不得不使用generic模板大多数控制(API Docs

这是发送两条消息的功能与预览图像和动作按钮:

function sendNewsMessage(recipientId) { 
 
    var messageData = { 
 
    recipient: { 
 
     id: recipientId 
 
    }, 
 
    message: { 
 
     attachment: { 
 
     type: "template", 
 
     payload: { 
 
      template_type: "generic", 
 
      elements: [{ 
 
      title: "Serie: Fischer im Recht", 
 
      subtitle: "Thomas Fischer ist Bundesrichter in Karlsruhe und schreibt für ZEIT und ZEIT ONLINE über Rechtsfragen.", 
 
      item_url: "http://www.zeit.de/serie/fischer-im-recht",    
 
      image_url: "http://img.zeit.de/autoren/F/Thomas_Fischer/thomas-fischer/wide__300x200__desktop", 
 
      buttons: [{ 
 
       type: "web_url", 
 
       url: "http://www.zeit.de/serie/fischer-im-recht", 
 
       title: "Zur Serie" 
 
      }, { 
 
       type: "postback", 
 
       title: "Abonnieren", 
 
       payload: "subscribe-fischer", 
 
      }], 
 
      }, { 
 
      title: "Redaktionsempfehlungen", 
 
      subtitle: "Besonders wichtige Nachrichten und Texte von ZEIT ONLINE", 
 
      item_url: "http://www.zeit.de/administratives/wichtige-nachrichten",    
 
      image_url: "http://img.zeit.de/angebote/bilder-angebotsbox/2016/bild-angebotsbox-48.jpg/imagegroup/wide", 
 
      buttons: [{ 
 
       type: "web_url", 
 
       url: "http://www.zeit.de/administratives/wichtige-nachrichten", 
 
       title: "Zur Übersicht" 
 
      }, { 
 
       type: "postback", 
 
       title: "Abonnieren", 
 
       payload: "subscribe-news", 
 
      }] 
 
      }] 
 
     } 
 
     } 
 
    } 
 
    }; 
 
    callSendAPI(messageData); 
 
}

这样您就可以发送图像链接而不是发送附件。

-1

您可以发送图像不作为附件,但通过网址,因此它会生成一个预览。

function sendPictureMessage(sender, url, callback) { 
    var temp = {}; 
    messageData = { 
    "attachment":{ 
     "type":"image", 
     "payload":{ 
     "url":url 
     } 
    } 
    }; 
    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.error('Error sending messages: ', error) 
    } else if (response.body.error) { 
     console.error('Error: ', response.body.error) 
    } 
    if (callback) 
     return callback(body); 
    }) 
} 

在此处指定网址。

相关问题