首页 > 解决方案 > Twilio 函数 - 访问传入消息信息

问题描述

我正在尝试使用 twilio 函数将传入的消息数据写入数据库。如何访问传入的消息数据(.from、.body)以在函数内提供给我的数据库?

这是我尝试过的 - 使用 context.from 和 context.body 来获取传入的消息电话号码和消息正文。数据库记录插入有效,但电话和正文的数据为空白。我不认为“context.from”和“context.body”是访问该数据的正确方法。

我的功能....

const airtable = require("airtable");
const twilio = require("twilio");

exports.handler = function (context, event, callback) {
 const base = new airtable({
   apiKey: context.AIRTABLE_API_KEY,
 }).base(context.AIRTABLE_BLUE_LIGHTNING);
 base("feed").create(
   [
     {
       fields: {
         phone: context.from,
         MSG: context.body,
       },
     },
   ],
   function (error, records) {
     if (error) {
       console.error(error);
       callback(error);
       return;
     } else {
       callback(null, "Success!");
     }
   }
 );
};

标签: node.jsfunctiontwilio

解决方案


event.from调用参数。 context.YOUR_STORED_VARIABLE调用您存储在配置选项卡中的任何环境变量


推荐阅读