我可以把许多图片链接放在对话流中,只随机发送一个吗



我是对话流的新手。我在上个月学到了一些东西,但我仍在寻找如何将大量图片放在意图中,并只向用户发送一张,而不是所有图片,以及随机发送,例如文本响应,作为Agent内部的一种娱乐。。。注:我已将客户端链接到Facebook Messenger,并希望将照片发送到那里我能做这个吗?

假设您正在使用Dialogflow实现库来响应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])

您可以采用这个概念并将其应用于您想要的任何响应类型。

希望这对你有用!

最新更新