简体   繁体   English

如何从Webhook URL桥接到HTTP POST请求?

[英]How to bridge from a webhook URL to a HTTP POST request?

I want to make a HTTP POST request to Twilio but the calling service only allows me to enter a webhook URL. 我想向Twilio发出HTTP POST请求,但呼叫服务仅允许我输入Webhook URL。

I was trying to bridge this with apigee's API proxy but I could not figure out how to make it work. 我试图将其与apigee的API代理进行桥接,但是我不知道如何使它起作用。

The flow is like this: A chat bot on motion.ai calls a web hook URL at a certain point. 流程是这样的:motion.ai上的聊天机器人在某个点调用了Web挂钩URL。 The call should make an outbound call via twilio.com which requires a HTTP POST request, see here . 该呼叫应通过twilio.com进行出站呼叫,这需要HTTP POST请求,请参见此处

The POST request looks like this: POST请求如下所示:

$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/<...>/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=<...>" \
    --data-urlencode "From=<...>" \
    -u '<...>:<...>'

What is the easiest way to bridge this? 架起桥梁的最简单方法是什么?

I managed to setup an API proxy with Apigee to convert the HTTP GET request to a HTTP POST request. 我设法通过Apigee设置了一个API代理,以将HTTP GET请求转换为HTTP POST请求。

Create a API proxy in Apigee and add a Basic Authentication policy: Apigee中创建API代理并添加Basic Authentication策略:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<BasicAuthentication async="false" continueOnError="false" enabled="true" name="Basic-Authentication-1">
    <DisplayName>Basic Authentication-1</DisplayName>
    <Operation>Encode</Operation>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <User ref="request.queryparam.username"/>
    <Password ref="request.queryparam.password"/>
    <AssignTo createNew="false">request.header.Authorization</AssignTo>
    <Source>request.header.Authorization</Source>
</BasicAuthentication>

Next add a Assign Message policy: 接下来添加一个Assign Message策略:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>ConvertQueryToFormParameters</DisplayName>
    <Properties/>
    <Copy source="request">
        <Headers/>
        <QueryParams/>
        <FormParams/>
        <Payload/>
        <Verb/>
        <StatusCode/>
        <ReasonPhrase/>
        <Path/>
    </Copy>
    <Add/>
    <Set>
        <FormParams>
            <FormParam name="To">{request.queryparam.To}</FormParam>
            <FormParam name="From">{request.queryparam.From}</FormParam>
            <FormParam name="Url">{request.queryparam.Url}</FormParam>
        </FormParams>
        <Verb>POST</Verb>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

Then you can make a POST request to Twilio by simply calling https://<yourApigeeApiUrl>.apigee.net/<yourApiName>?username=<yourTwilioApiUsername>&password=<yourTwilioApiPassword>&... 然后您可以通过简单地调用https://<yourApigeeApiUrl>.apigee.net/<yourApiName>?username=<yourTwilioApiUsername>&password=<yourTwilioApiPassword>&...向Twilio发出POST请求https://<yourApigeeApiUrl>.apigee.net/<yourApiName>?username=<yourTwilioApiUsername>&password=<yourTwilioApiPassword>&...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM