gpt4 book ai didi

json - Azure 自动化 Webhook - Twilio StatusCallback 未到达 JSON

转载 作者:行者123 更新时间:2023-12-03 00:47:02 25 4
gpt4 key购买 nike

我正在尝试基于 Twilio、Azure 自动化和 SCOM 实现一个解决方案,当某个事件发生时自动调用某人。此外,应该可以有人调用一个号码,并触发相同的过程。

Twilio 帐户/电话号码已设置并且工作正常。当我调用 Twilio Number 时,我在 Azure 自动化 Webhook 上成功接收到 HTTP POST,并触发了 Runbook。

我现在面临的唯一问题是我无法使用 cmdlet ConvertFrom-Json提取 WebhookBody。

这是我在使用 cmdlet 时遇到的错误:

ConvertFrom-JSON : Invalid JSON primitive: Called. At line:13 char:11 + $Inputs = ConvertFrom-JSON $webhookdata.RequestBody + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [ConvertFrom-Json], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand



这是从 Twilio 到达 Azure 自动化 Webhook 的输入:

{"WebhookName":"Twilio Endpoint","RequestBody":"Called=%2B41815880262&ToState=Chur&CallerCountry=CH&Direction=inbound&Timestamp=Fri%2C%2010%20Feb%202017%2009%3A07%3A35%20%2B0000&CallbackSource=call-progress-events&CallerState=&ToZip=&SequenceNumber=0&CallSid=CA7c152287d945595fe600614fe7778f8a&To=%2B41815880262&CallerZip=&ToCountry=CH&ApiVersion=2010-04-01&CalledZip=&CalledCity=&CallStatus=completed&Duration=1&From=%2BMYTELNUZMBER&CallDuration=8&AccountSid=MYSID&CalledCountry=CH&CallerCity=&Caller=%2Bmybnumber&FromCountry=CH&ToCity=&FromCity=&CalledState=Chur&FromZip=&FromState=","RequestHeader":{"Cache-Control":"max-age=259200","Connection":"close","Accept":"/","Host":"s2events.azure-automation.net","User-Agent":"TwilioProxy/1.1","X-Twilio-Signature":"pq2jYVGN3H5LmanwId0xCvp69tM=","x-ms-request-id":"bc1cf55a-33b2-4046-a343-199d1a7fac4a"}}



当我用这个 cmd 简单地输出 WebHook 数据时,我可以看到 Twilio Repsonse 看起来有些奇怪(不过,Heade 看起来不错):
$WebhookName = $WebhookData.WebhookName
$WebhookHeaders = $WebhookData.RequestHeader
$WebhookBody = $WebhookData.RequestBody

Write-Output $WebhookHeaders
Write-Output $WebhookBody

输出:

Cache-Control : max-age=259200 Connection : close Accept : / Host : s2events.azure-automation.net User-Agent
: TwilioProxy/1.1 X-Twilio-Signature : xmEbt23prT+W8zJrRZE5pdKullE= x-ms-request-id : bdca412c-584e-42ba-acbb-969cdf9c1ec0

Called=%2B41815880262&ToState=Chur&CallerCountry=CH&Direction=inbound&Timestamp=Wed%2C%2008%20Feb%202017%2013%3A18%3A27%20%2B0000&CallbackSource=call-progress-events&CallerState=&ToZip=&SequenceNumber=0&CallSid=CALLSID&To=%2B41815880262&CallerZip=&ToCountry=CH&ApiVersion=2010-04-01&CalledZip=&CalledCity=&CallStatus=completed&Duration=1&From=%2BMYNUMBER&CallDuration=7&AccountSid=MYSID&CalledCountry=CH&CallerCity=&Caller=%2BMYBNUMBER&FromCountry=CH&ToCity=&FromCity=&CalledState=Chur&FromZip=&FromState=



有没有人知道我可以做什么而不是编写自己的“转换器”来从 TWILIO HTTP POST 获取值?或者我可能做错了什么可怕的事情?

最佳答案

所以,我想我理解你的问题。你做的有点不对:$webhook data 已经是一个对象,它拥有你需要的一切:

$WebhookData.WebhookName
$WebhookData.RequestHeader
$WebhookData.RequestBody

你只需要解析 RequestBody变成有意义的东西:
$data = @{ };

foreach ($item in $WebhookData.RequestBody.Split('&')) {
try {
$item = $item.Split('=');
$data.Add($item[0], [System.Net.WebUtility]::UrlDecode($item[1]))
}
catch {
Write-Warning -Message ('Possible null parameter value for {0}' -f $item[0]);
}
}

关于json - Azure 自动化 Webhook - Twilio StatusCallback 未到达 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42156503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com