2016-11-10 7 views
1

Я пытаюсь создать бот fb_messenger, используя wit.ai.In wit.ai, я могу отвечать только на вопрос и отвечать только на текст. Но я хочу ответить на вопрос, показывая изображения. Как это сделать? веди меня. спасибо.Как ответить изображениями в wit.ai?

ответ

0

Вам необходимо отправить изображение в Wit действия с помощью мессенджера Bot:

Пример, если вы используете Node 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) 
}, 

Не забудьте удалить часть «Bot посылает» из вашей истории на Wit.ai, поэтому вы не отправляете изображение и URL.

Надеюсь, это поможет!

0

Вам необходимо использовать шаблон прикрепления изображения.

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>" 

Дополнительная информация here:

 Смежные вопросы

  • Нет связанных вопросов^_^