Google 个应用程序正在解析 JSON 个问题
Parsing JSON Issue with Google Apps
我无法使用 Google 应用程序解析 JSON。有效负载来自 Microsoft Teams。当我使用 json.postData.getDataAsString() 转储有效载荷信息时,我收到以下信息:
{"type":"message",
"Id":"1490878296446",
"timestamp":"2017-03-30T12:51:36.857Z",
"localTimestamp":null,
"serviceUrl":"https://smba.trafficmanager.net/amer-client-ss.msg/",
"channelId":"msteams",
"from":{"id":"394724749272","name":"Test, User"},
"conversation":{"isGroup":true,"id":"39482095823@thread.skype;messageid=1490878296446","name":null},
"Recipient":null,
"textFormat":"plain",
"attachmentLayout":null,
"membersAdded":null,
"membersRemoved":null,
"topicName":null,
"historyDisclosed":null,
"Locale":null,
"text":"Test message",
"Summary":null,
"attachments":[{"contentType":"text/html","contentUrl":null,"content":"<div><span contenteditable=\"false\" itemscope=\"\" itemtype=\"http://schema.skype.com/Mention\" itemid=\"0\">Testing</span><span contenteditable=\"false\" itemscope=\"\" itemtype=\"http://schema.skype.com/Mention\" itemid=\"1\"></span> Hi there</div>","name":null,"thumbnailUrl":null}],
"entities":[{"type":"mention","mentioned":{"id":"28:22e50a9b-80cc-4eab-a092-ce64796d28d7","name":""}},{"type":"clientInfo","locale":"en-US","country":"US","platform":"Windows"}],
"channelData":{"teamsChannelId":"19:c5a0767fdc434c8097444a6f7488ae6d@thread.skype","teamsTeamId":"984720987342876876@thread.skype","channel":{"id":"2098374239872-7@thread.skype"},"team":{"id":"19:8fce7e8df8084d62bc0ddb5d77830131@thread.skype"},"onBehalfOf":"[{\"itemid\":0,\"mri\":\"1f265431-39ad-43f7-8dbe-93ee5cc43777\",\"mentionType\":\"webhook\",\"displayName\":\"Testing\"}]","tenant":{"id":"cf857d10-00c4-44ac-8e8a-33f3f8a6d701"}},"action":null,"replyToId":null,"value":null}
像我在 Slack 中那样使用点语法并不能让我深入研究该有效负载。这是我尝试使用的代码:
function doPost(json) {
var parameters = json.parameters;
var text = String(parameters);
var datetime = new Date();
var date = datetime.toDateString();
var spreadsheet = SpreadsheetApp.openById('myspreadsheetid');
var sheet = spreadsheet.getSheetByName('mysheetname');
sheet.appendRow([text,date])
};
以上内容适用于来自 Slack webhook 的负载。这是有效载荷的样子:
token=fihwEGHwpoerihKe&team_id=T04U18AG8
&team_domain=mydomain&service_id=234211
&channel_id=C2QJ4SQL0
&channel_name=testchannel
×tamp=1490881481.055677
&user_id=U0KDGEBJB
&user_name=test.user
&text=my test message
&trigger_word=my test message
虽然我不明白为什么这是必要的,但解决方案如下:
首先我需要将 MSTeams 有效负载转换为字符串,然后将其解析为对象。删除其中任何一个步骤或更改顺序都不起作用。
function doPost(json) {
var jsonstring = json.postData.getDataAsString()
var jsonobject = JSON.parse(jsonstring);
var text = String(jsonobject.text);
...//the rest of the webapp follows
我无法使用 Google 应用程序解析 JSON。有效负载来自 Microsoft Teams。当我使用 json.postData.getDataAsString() 转储有效载荷信息时,我收到以下信息:
{"type":"message", "Id":"1490878296446", "timestamp":"2017-03-30T12:51:36.857Z", "localTimestamp":null, "serviceUrl":"https://smba.trafficmanager.net/amer-client-ss.msg/", "channelId":"msteams", "from":{"id":"394724749272","name":"Test, User"}, "conversation":{"isGroup":true,"id":"39482095823@thread.skype;messageid=1490878296446","name":null}, "Recipient":null, "textFormat":"plain", "attachmentLayout":null, "membersAdded":null, "membersRemoved":null, "topicName":null, "historyDisclosed":null, "Locale":null, "text":"Test message", "Summary":null, "attachments":[{"contentType":"text/html","contentUrl":null,"content":"<div><span contenteditable=\"false\" itemscope=\"\" itemtype=\"http://schema.skype.com/Mention\" itemid=\"0\">Testing</span><span contenteditable=\"false\" itemscope=\"\" itemtype=\"http://schema.skype.com/Mention\" itemid=\"1\"></span> Hi there</div>","name":null,"thumbnailUrl":null}], "entities":[{"type":"mention","mentioned":{"id":"28:22e50a9b-80cc-4eab-a092-ce64796d28d7","name":""}},{"type":"clientInfo","locale":"en-US","country":"US","platform":"Windows"}], "channelData":{"teamsChannelId":"19:c5a0767fdc434c8097444a6f7488ae6d@thread.skype","teamsTeamId":"984720987342876876@thread.skype","channel":{"id":"2098374239872-7@thread.skype"},"team":{"id":"19:8fce7e8df8084d62bc0ddb5d77830131@thread.skype"},"onBehalfOf":"[{\"itemid\":0,\"mri\":\"1f265431-39ad-43f7-8dbe-93ee5cc43777\",\"mentionType\":\"webhook\",\"displayName\":\"Testing\"}]","tenant":{"id":"cf857d10-00c4-44ac-8e8a-33f3f8a6d701"}},"action":null,"replyToId":null,"value":null}
像我在 Slack 中那样使用点语法并不能让我深入研究该有效负载。这是我尝试使用的代码:
function doPost(json) {
var parameters = json.parameters;
var text = String(parameters);
var datetime = new Date();
var date = datetime.toDateString();
var spreadsheet = SpreadsheetApp.openById('myspreadsheetid');
var sheet = spreadsheet.getSheetByName('mysheetname');
sheet.appendRow([text,date])
};
以上内容适用于来自 Slack webhook 的负载。这是有效载荷的样子:
token=fihwEGHwpoerihKe&team_id=T04U18AG8
&team_domain=mydomain&service_id=234211
&channel_id=C2QJ4SQL0
&channel_name=testchannel
×tamp=1490881481.055677
&user_id=U0KDGEBJB
&user_name=test.user
&text=my test message
&trigger_word=my test message
虽然我不明白为什么这是必要的,但解决方案如下:
首先我需要将 MSTeams 有效负载转换为字符串,然后将其解析为对象。删除其中任何一个步骤或更改顺序都不起作用。
function doPost(json) {
var jsonstring = json.postData.getDataAsString()
var jsonobject = JSON.parse(jsonstring);
var text = String(jsonobject.text);
...//the rest of the webapp follows