如何使Chatfuel读取存储在Zapier中的JSON文件?

问题描述 投票:0回答:1

在我的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

enter image description here

enter image description here

Zapier Webhook成功获取JSON并将其发送到存储。

enter image description here

enter image description here

设置键值对,然后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"}]}

也就是说,有两个mais问题:

1)JSON中缺少“{[”

2)JSON将新信息附加到现有JSON,而不是生成全新的JSON,这导致JSON有5个不同的部分。

我正在寻找这个问题的可能解决方案。

python json zapier chatfuel zapier-cli
1个回答
0
投票

大卫来自Zapier平台团队。

首先,您不需要钥匙周围的报价,我们会为您处理。目前,您的json将如下所示:

{ "'messages'": { "'text'": "<DATA FROM STEP 1>" } }

所以第一个改变是取出那些。

接下来,如果要存储数组,请改用Push Value Onto List操作。它需要一个顶级键并将您的值存储在名为list的对象中的键中。鉴于以下设置:

JSON中生成的结构是

{ "demo": {"list": [ "5" ]} }

看起来你想要存储额外的水平;一组json对象:

[ { "text": "this is text" } ]

这不是开箱即用的,因为所有列表项都存储为字符串。您可以存储json字符串,并在需要像对象一样访问它们时将它们解析回对象!

这是否回答你的问题?

© www.soinside.com 2019 - 2024. All rights reserved.