如何解析来自 Slack 的交互消息?

How to parse interaction messages coming from Slack?

我想解析来自 Slack 的交互消息请求。这就是 Slack 在 their docs:

中所说的

The body of that request will contain a payload parameter. Your app should parse this payload parameter as JSON.

这看起来很简单,所以我这样分析它:

JSON.parse(decodeURIComponent(body.split('=')[1]))

但是,在结果对象的字符串字段中,我看到的是加号而不是空格:

"There+should+not+be+pluses+here"

我做错了什么?

看了一下their library here,原来他们用的是node的querystring.parse().

所以解析过程应该是这样的:

JSON.parse(querystring.parse(body).payload)