我想在通用模板聊天机器人中随机化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
你知道如何改变答案吗?
答案 0 :(得分:0)
将元素视为$数组。你需要的只是在发送模板之前改组元素数组。