2016-11-20 122 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); 
    }) 
} 

在此處指定網址。

相關問題