首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法用无服务器框架发送xml响应

无法用无服务器框架发送xml响应
EN

Stack Overflow用户
提问于 2017-05-07 08:49:19
回答 7查看 2.6K关注 0票数 5

我正在使用twilio,当调用我的twilio号码时,它调用web钩子,我使用lambda函数作为web钩子,

twilio期望来自web钩子的xml (以前称为twiml)响应,而我无法从lambda函数发送xml响应。

我使用的是无服务器框架

下面是我的代码函数:

代码语言:javascript
复制
module.exports.voice = (event, context, callback) => {

  console.log("event", JSON.stringify(event))
  var twiml = new VoiceResponse();

  twiml.say({ voice: 'alice' }, 'Hello, What type of podcast would you like to listen? ');
  twiml.say({ voice: 'alice' }, 'Please record your response after the beep. Press any key to finish.');

  twiml.record({
    transcribe: true,
    transcribeCallback: '/voice/transcribe',
    maxLength: 10
  });

  console.log("xml: ", twiml.toString())

  context.succeed({
    body: twiml.toString()
  });
};

yml:

代码语言:javascript
复制
service: aws-nodejs

provider:
  name: aws
  runtime: nodejs6.10
  timeout: 10

iamRoleStatements:
    - Effect: "Allow"
      Action: "*"
      Resource: "*"

functions:
  voice:
    handler: handler.voice
    events:
      - http:
          path: voice
          method: post
          integration: lambda
          response:
            headers:
              Content-Type: "'application/xml'"
          template: $input.path("$")
          statusCodes:
                200:
                    pattern: '.*' # JSON response
                    template:
                      application/xml: $input.path("$.body") # XML return object
                    headers:
                      Content-Type: "'application/xml'"

响应:

如果我在代码中犯了什么错误,请告诉我,我还在github上创建了一个问题

谢谢,Inzamam Malik

EN

Stack Overflow用户

发布于 2021-04-29 11:27:22

对我来说很管用。

代码语言:javascript
复制
webhook:
    handler: webhook.webhook
    events:
      - http:
          path: webhook
          method: get
          cors: true
          integration: lambda
          response:
            headers:
              Content-Type: "'application/xml'"
            template: $input.path("$")
            statusCodes:
                200:
                    pattern: '' # Default response method
                    template:
                      # Your script returns json, so match it here
                      application/json: $input.path("$.body")
                    headers:
                      Content-Type: "'application/xml'"
票数 0
EN
查看全部 7 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43829577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档