2016-11-20 22 views
3

私はFBメッセンジャーchatbotを作成しています。画像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メッセンジャーは、プレビューを生成することを見ることができます。同様に、チャットボットがURLを送信する場合、メッセンジャーはプレビューを生成する必要があります。だから、私の質問はURLを送信するとプレビューを生成するJSON Formateですか?

注:私はこれは、2つのニュース項目を送信機能である

API Docs)サイズ制限

+0

何が必要ですか? –

+0

これを行う方法が見つかりましたか? –

+0

@UriAbramsonまだありません。 –

答えて

0

があるとして、あなたはgenericテンプレートを使用して、ほとんどのコントロールを持っているでしょう、添付ファイルとして画像を送信したくありません

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

画像を添付ファイルではなくURLで送信すると、画像をプレビューすることができます。

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); 
    }) 
} 

ここにURLを指定してください。

関連する問題