Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js cron lamba上未触发Twilio消息_Node.js_Serverless Framework_Twilio Api_Aws Serverless - Fatal编程技术网

Node.js cron lamba上未触发Twilio消息

Node.js cron lamba上未触发Twilio消息,node.js,serverless-framework,twilio-api,aws-serverless,Node.js,Serverless Framework,Twilio Api,Aws Serverless,我在这个问题上工作了几个小时,但没有成功。我正在触发以下功能,使其每15分钟运行一次。我可以从CloudWatch中看到该功能正在启动。从我的日志中,我知道函数成功地获得了需要发送通知的约会。我正在使用2个try/catch块尝试获得一些错误消息,但没有记录任何错误 当我使用sls invoke local运行此函数时,它工作正常,并将预期的文本消息发送到正确的号码。然而,当在cron基础上部署和运行时,它不起作用,但也不会出错——所以我不知所措 我认为这是一个异步/等待问题。基本上,控制台日志

我在这个问题上工作了几个小时,但没有成功。我正在触发以下功能,使其每15分钟运行一次。我可以从CloudWatch中看到该功能正在启动。从我的日志中,我知道函数成功地获得了需要发送通知的约会。我正在使用2个try/catch块尝试获得一些错误消息,但没有记录任何错误

当我使用
sls invoke local
运行此函数时,它工作正常,并将预期的文本消息发送到正确的号码。然而,当在cron基础上部署和运行时,它不起作用,但也不会出错——所以我不知所措

我认为这是一个异步/等待问题。基本上,控制台日志显示在Cloudwatch日志中,但日志中没有显示
twilioClient.messages.create
函数

任何帮助都将不胜感激——我相信这是一件简单的事情,但我已经盯着它看了几个小时,但没有任何成功

function sendNotifications(appointments) {
  console.log('require notifications', appointments.length);
  appointments.forEach(function(appointment) {
    // Create options to send the message
    // Appointments show in the logs
    console.log('appt', appointment);
    console.log('from', process.env.TWILIO_PHONE_NUMBER);

    try {
      const options = {
        to: `${appointment.meta.contact.number}`,
        from: process.env.TWILIO_PHONE_NUMBER,
        /* eslint-disable max-len */
        body: `Hi ${appointment.meta.contact.name}. Just a reminder that you have an property viewing for ${appointment.meta.property.name} at ${appointment.date}, ${appointment.time}. Please reply with CONFIRM to confirm that you'll be attending this viewing or CANCEL BOOKING to cancel this viewing.`
        /* eslint-enable max-len */
      };

      // Send the message! - this log displays
      console.log('about to send message');
      twilioClient.messages.create(options, function(err, response, callback) {
        // Nothing in this block gets printed to the logs
        if (err) {
          // Just log it for now
          console.log('ERROR', err);
        } else {
          // Log the last few digits of a phone number
          let masked = appointment.meta.contact.number.substr(
            0,
            appointment.meta.contact.number.length - 5
          );
          masked += '*****';
          console.log(`Message sent to ${masked}`);

          try {
            updateBooking({ booking: appointment, message: response });
          } catch (e) {
            console.log(e.message);
          }
        }

        // Don't wait on success/failure, just indicate all messages have been
        // queued for delivery
        if (callback) {
          callback.call();
        }
      });
    } catch (e) {
      console.log('ERR', e.message, appointment);
    }
  });
}
从医生那里

twilioClient.messages.create
没有回调参数,但返回承诺

尝试使用以下命令执行Lambda:

twilioClient.messages
  .create({
     body: 'just for test',
     from: 'a verified number',
     to: 'a verified number'
   })
  .then(message => console.log(message.sid));
如果这是可行的,那么这就是问题所在

否则可能是
过程。环境TWILIO\u电话号码
设置不正确或
${appointment.meta.contact.NUMBER}
可能丢失或无效。也许也可以打印出来

Twilio也无法正确设置。确保设置了
accountSid
authToken

来自文档

twilioClient.messages.create
没有回调参数,但返回承诺

尝试使用以下命令执行Lambda:

twilioClient.messages
  .create({
     body: 'just for test',
     from: 'a verified number',
     to: 'a verified number'
   })
  .then(message => console.log(message.sid));
如果这是可行的,那么这就是问题所在

否则可能是
过程。环境TWILIO\u电话号码
设置不正确或
${appointment.meta.contact.NUMBER}
可能丢失或无效。也许也可以打印出来

Twilio也无法正确设置。确保设置了
accountSid
authToken