node.js - 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!");
}
}
);
};
解决方案
event.from
调用参数。
context.YOUR_STORED_VARIABLE
调用您存储在配置选项卡中的任何环境变量
推荐阅读
- c++ - 为什么 const 成员可以初始化两次?
- php - 维度的 preg_match
- ios - Twitter 喜欢侧边菜单、导航抽屉或滑动菜单 - iOS Swift
- java - Overdraw Eclipse RCP 应用程序的主外壳
- java - 当前屏幕上的 JavaFX 警报
- firebase - 静态页面(托管)的firebase中间件功能
- msbuild - MSBuild 是否支持 .Net Core 项目
- jquery - 将评论添加到它所属的评论列表中
- android - Zbar 没有释放相机(kitkat 上的问题)android
- javascript - 将值分配给单个数组项并调用它们