Twilio Studio:将 SMS 对话日志转发到电子邮件 [英] Twilio Studio: Forward SMS conversation log to email

查看:29
本文介绍了Twilio Studio:将 SMS 对话日志转发到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SMS Studio 与入站 SMS 消息进行快速聊天机器人对话,并希望在对话日志完成后将对话日志转发到电子邮件.我编写了一个使用 SendGrid API 的函数来 将短信转发到电子邮件.它独立工作 - 即,如果我将电话号码配置为在文本输入时立即运行该功能,它将通过电子邮件发送该单个 SMS 输入.

I'm using SMS studio do have a quick chat bot conversation with inbound SMS messages, and would like to forward the conversation log to email after it's complete. I've written a function that uses the SendGrid API to forward SMSes to email. It works independently - ie, if I configure the phone number to run the function immediately as a text comes in, it will email that single SMS input.

但是,我想将该功能添加到 Twilio Studio 流程的末尾,以便在结束后通过电子邮件将整个对话日志发送给我.一旦我将该函数附加到工作室流程的末尾,它就会停止工作,并且我会收到一条失败通知.

However, I'd like to add the function to the end of of Twilio Studio flow, so that it emails the entire log of the conversation to me, once it's over. Once I append the function to the end of the studio flow, it stops working, and I get a failure notice.

这是函数中的代码:

const got = require('got');

exports.handler = function(context, event, callback) 
{
    const requestBody = {
    personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
    from: { email: context.FROM_EMAIL_ADDRESS },
    subject: `New SMS message from: ${event.From}`,
    content: [
      {
        type: 'text/plain',
        value: event.Body
      }
    ]
}

  got.post('https://api.sendgrid.com/v3/mail/send', {
    headers: {
      Authorization: `Bearer ${context.SENDGRID_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(requestBody)
  })
    .then(response => {
      let twiml = new Twilio.twiml.MessagingResponse();
      callback(null, twiml);
    })
    .catch(err => {
      callback(err);
    });

};`

这是调试器返回的错误,如果我将此函数作为 Twilio Studio 流程中的最后一步:

Here's the error the debugger returns, if I make this function the last step in a Twilio studio flow:

错误 - 81017
Twilio 函数响应错误
从附加到 Studio 流的 Twilio 函数返回的响应中出现错误.
可能的原因
您的函数在响应之前超时
您的函数返回了错误响应
可能的解决方案
您的函数必须包含回调.
确保将函数回调 callback(err, response) 正确放置在函数代码中.
如果您使用 JavaScript 承诺,请确保在成功和捕获块中调用回调.
您的函数响应错误.

Error - 81017
Error on Twilio Function response
There was an error in the response back from a Twilio Function attached to the Studio flow.
Possible Causes
Your Function timed out before responding
Your Function returned an error response
Possible Solutions
Your Function must contain a callback.
Make sure you place the Function callback callback(err, response) is placed correctly in your Function code.
If you are using a JavaScript promise, make sure the callback is called in both success and catch blocks.
Your Function responded with an error.

我很难弄清楚错误是什么.有人有什么建议吗?

I'm having a hard time figuring out what the error is. Does anyone have any tips?

谢谢!

推荐答案

来自 Twilio 的 Jarod.我实际上写了一个与此非常相似的应用程序.代码对我来说看起来不错.通常当人们遇到这种性质的错误时,它来自 SendGrid 承诺.这里有两个提示:

Jarod from Twilio. I actually wrote an app very similar to this. Code looks good to me. Often when people encounter an error of this nature it is coming from the SendGrid promise. Here are two tips:

  1. 如果在测试时让函数保持打开状态,您实际上可以记录错误并查看函数的响应.日志将在底部.这些通常有更多的信息.
  2. 检查您使用的出站电子邮件地址是否已在您的 SendGrid 帐户中列入白名单 Whitelabel - Sendgrid
  3. 确保您已将环境变量添加到 Functions 配置中.Twilio 功能配置 - 控制台

希望有帮助!如果有更多问题,请随时发送电子邮件至 support@twilio.com.

Hope that helps! If not feel free to email support@twilio.com with more questions.

这篇关于Twilio Studio:将 SMS 对话日志转发到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆