在我的 Chatfuel 块中,我收集了一个 {{user input}} 并在 Zapier webhook 中发布了一个 JSON。到目前为止,一切都很好。之后,我的本地 Pyhon 从 Zapier 存储中成功读取了这个 JSON
url = 'https://store.zapier.com/api/records?secret=password'
response = urllib.request.urlopen(url).read().decode('utf-8')
data = json.loads(response)
并分析它生成另一个 JSON 作为输出:
json0={
"messages": [
{"text": analysis_output}]
}
然后 Python3 在 Zapier 的 GET webhook 中发布这个 JSON:
import requests
r = requests.post('https://hooks.zapier.com/hooks/catch/2843360/8sx1xl/', json=json0)
r.status_code
Zapier Webhook 成功获取 JSON 并将其发送到 Storage。
设置键值对,然后 Chatfuel 尝试从存储中读取:
GET https://store.zapier.com/api/records?secret=password2
但是得到的 JSON 结构是错误的,用这段代码验证了什么:
url = 'https://store.zapier.com/api/records?secret=password2'
response = urllib.request.urlopen(url).read().decode('utf-8')
data = json.loads(response)
data
返回:
{'messages': "text: Didn't know I could order several items"}
Chatfuel 工作的正确时间应该是:
{'messages': [{"text: Didn't know I could order several items"}]}
也就是说,有两个主要问题:
1) JSON 中缺少“{ [”
2) JSON 将新信息附加到现有信息,而不是生成全新的 JSON,导致 JSON 有 5 个不同部分。
我正在为这个问题寻找可能的解决方案。