我可以在对话流中放置许多图片链接并只随机发送一个吗
Can i put Many Pictures links in dialogflow and send only one Randomly
我是 dialogflow 的新手。上个月我学到了一些东西,但我仍在寻找如何将大量图片放在意图中并只向用户发送一张,而不是全部,并且是随机的,例如文本回复作为一种娱乐方式代理人 ...
笔记 :
我将客户端链接到 Facebook Messenger,我想将照片发送到那里
我可以这样做吗?
假设您正在使用 Dialogflow-fulfillment 库来响应 webhook 请求,这应该可以解决问题。
您可以将要发送的任何类型的响应存储在数组中...
例如,我将选择一组纯文本回复
const responses = [
"I didn't get that. Can you say it again?",
'I missed what you said. What was that?',
'Sorry, could you say that again?',
'Sorry, can you say that again?',
'Can you say that again?',
"Sorry, I didn't get that. Can you rephrase?",
'Sorry, what was that?',
'One more time?',
'What was that?',
'Say that one more time?',
"I didn't get that. Can you repeat?",
'I missed that, say that again?'
]
给定数组,您可以生成一个介于 0(大多数编程语言从 0 开始索引)和数组长度之间的随机数。
const index = Math.floor((Math.random() * responses.length) + 1)
在上面的例子中,索引被分配给0到11之间的任意数字。然后您可以将这个索引传递到数组中以随机选择1个值。
agent.add(responses[index])
您可以采用此概念并将其应用于您想要的任何响应类型。
希望这对您有用!
我是 dialogflow 的新手。上个月我学到了一些东西,但我仍在寻找如何将大量图片放在意图中并只向用户发送一张,而不是全部,并且是随机的,例如文本回复作为一种娱乐方式代理人 ... 笔记 : 我将客户端链接到 Facebook Messenger,我想将照片发送到那里 我可以这样做吗?
假设您正在使用 Dialogflow-fulfillment 库来响应 webhook 请求,这应该可以解决问题。
您可以将要发送的任何类型的响应存储在数组中...
例如,我将选择一组纯文本回复
const responses = [
"I didn't get that. Can you say it again?",
'I missed what you said. What was that?',
'Sorry, could you say that again?',
'Sorry, can you say that again?',
'Can you say that again?',
"Sorry, I didn't get that. Can you rephrase?",
'Sorry, what was that?',
'One more time?',
'What was that?',
'Say that one more time?',
"I didn't get that. Can you repeat?",
'I missed that, say that again?'
]
给定数组,您可以生成一个介于 0(大多数编程语言从 0 开始索引)和数组长度之间的随机数。
const index = Math.floor((Math.random() * responses.length) + 1)
在上面的例子中,索引被分配给0到11之间的任意数字。然后您可以将这个索引传递到数组中以随机选择1个值。
agent.add(responses[index])
您可以采用此概念并将其应用于您想要的任何响应类型。
希望这对您有用!