2016-11-10 2 views
1

Ich versuche einen fb_messenger-Bot mit wit.ai zu erstellen.In wit.ai kann ich nur antworten und fragen, was nur Text ist.Aber ich möchte dem Benutzer antworten, indem ich Bilder zeige.Wie geht das? Bitte führe mich. Vielen Dank.Wie antworten Sie mit Bildern in wit.ai?

Antwort

0

Sie müssen das Bild in Ihrer Wit Aktion zu senden, um den Messenger Bot mit:

Beispiel wenn Sie mit Knoten js:

const actions = { 
/** 
* This is used by the "Bot sends" action in Wit 
* @param sessionId 
* @param text 
* @returns {Promise.<T>} 
*/ 
send({sessionId}, {text}) { 
    // Our bot has something to say! 
    // Let's retrieve the Facebook user whose session belongs to 
    const recipientId = sessions[sessionId].fbid; 
    if (recipientId) { 
     // Yay, we found our recipient! 
     // Let's forward our bot response to her. 
     // We return a promise to let our bot know when we're done sending 
     //bot is a simple wrapper for Messenger node code provided [here][1] 
     return bot.sendTextMessage(recipientId, text) 
      .catch((err) => { 
       console.error(
        'Oops! An error occurred while forwarding the response to', 
        recipientId, 
        ':', 
        err.stack || err 
       ); 
      }); 
    } else { 
     console.error('Oops! Couldn\'t find user for session:', sessionId); 
     // Giving the wheel back to our bot 
     return Promise.resolve() 
    } 
}, 
['my-custom-action']({sessionId, context, entities, message}) { 
    //Api calls ... 
    //now i got an image URL i want to send to the user 
    return bot.sendImageMessage(recipientId, image_url); 

    return Promise.resolve(context) 
}, 

Vergessen Sie nicht, den Teil "Bot sendet" aus Ihrer Geschichte auf Wit.ai zu löschen, das heißt, Sie senden nicht sowohl das Bild als auch die URL.

Hoffe, das hilft!

0

Sie müssen die Bildanhangsvorlage verwenden.

curl -X POST -H "Content-Type: application/json" -d '{ 
    "recipient":{ 
    "id":"<USER_ID>" 
    }, 
    "message":{ 
    "attachment":{ 
     "type":"image", 
     "payload":{ 
     "url":"<IMAGE_URL>" 
     } 
    } 
    } 
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>" 

Weitere Informationen here:

Verwandte Themen