简体   繁体   English

部署后,为什么不快速回复我在Wit.ai上设置的对Facebook Messenger的工作?

[英]Why don't quick replies I set on Wit.ai work on facebook messenger when deployed?

I'm using Wit.ai to create a chatbot on facebook messenger. 我正在使用Wit.ai在facebook Messenger上创建聊天机器人。 However, if I set quick replies for a certain user input, having deployed the bot and entering said input, I only see the text that the quick reply buttons are supposed to follow. 但是,如果我为某个用户输入设置了快速回复,并且已经部署了漫游器并输入了该输入,那么我只会看到快速回复按钮应该遵循的文本。

I'm assuming you are using the messenger exemple in the Node.js SDK. 我假设您正在使用Node.js SDK中的Messenger示例。

This code does not support quickreplies. 此代码不支持快速答复。 First, you can use my code to implement the needed feature in the sendTextMessage function: 首先,您可以使用我的代码在sendTextMessage函数中实现所需的功能:

const sendMessage = (id, message) => {
  const body = JSON.stringify({
    recipient: { id },
    message: message,
  });
  const qs = 'access_token=' + encodeURIComponent(FB_PAGE_TOKEN);
  return fetch('https://graph.facebook.com/me/messages?' + qs, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body,
  })
  .then(rsp => rsp.json())
  .then(json => {
    if (json.error && json.error.message) {
      throw new Error(json.error.message);
    }
    return json;
  });
};

const sendTextMessage = (id, text, quickreplies) => {
  if(!quickreplies) return sendMessage(id, {text});

  if(quickreplies.length > 10) {
    throw new Error("Quickreplies are limited to 10");
  }

  let body = {text, quick_replies: []};
  quickreplies.forEach(qr => {
    body.quick_replies.push({
      content_type: "text",
      title: qr,
      payload: 'PAYLOAD' //Not necessary used but mandatory
    });
  });
  return sendMessage(id, body);
};

Second, you have to consider the quickreplies in the "send" action. 其次,您必须考虑“发送”操作中的快速答复。 Here is a very simple "send action" example: 这是一个非常简单的“发送操作”示例:

const actions = {
  send({sessionId}, {text, quickreplies}) {
    const recipientId = sessions[sessionId].fbid;
    return sendTextMessage(recipientId, text, quickreplies);
  }
}

EDIT: Also, note that the messenger quickreplies are limited to 20 characters. 编辑:另外,请注意,Messenger的快速回复仅限于20个字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM