【发布时间】:2018-01-09 16:39:26
【问题描述】:
在我的 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 个不同的部分。
我正在为这个问题寻找可能的解决方案。
【问题讨论】:
-
你好!您能否更新您的问题以准确包含您如何在存储中设置数据?此外,如有疑问,请将键的值设置为完整的 json,然后根据需要对其进行解析/转储。这样,Zapier 就不会弄乱您的数据存储方式。
-
问题已更新 xavdid
标签: python json zapier chatfuel zapier-cli