随机化chatbot Messenger通用模板中的按钮

时间:2016-11-17 12:21:39

标签: php arrays shuffle messenger chatbot

我想在通用模板聊天机器人中随机化Answer_A; Answer_B; Answer_C。

  "message":{
"attachment":{
  "type":"template",    
  "payload":{
    "template_type":"generic",
    "elements":[
      {
        "title":"' . $res ['Question'] . '",  
    "image_url":"' . $res ['Picture'] . '",       
        "buttons":[
          {
            "type":"postback",
            "title":"' . $res ['Answer_A'] . '",
            "payload":"Answer_A-' . $res ['id'] . '"
          },
          {
            "type":"postback",
            "title":"' . $res ['Answer_B'] . '",
            "payload":"Answer_B-' . $res ['id'] . '"
          },
      {
            "type":"postback",
            "title":"' . $res ['Answer_C'] . '",
            "payload":"Answer_C-' . $res ['id'] . '"
          }                               

这是一个简单的琐事聊天机器人,问题是从* csv文件中加载的:

Category;Question;Answer A;Answer B;Answer C;Correct Answer
Name;Sample question?;Lorem;Ipsum;Dolores;a

你知道如何改变答案吗?

1 个答案:

答案 0 :(得分:0)

将元素视为$数组。你需要的只是在发送模板之前改组元素数组。