我试图发送sms消息松弛,我有消息发布的地方 . 我遇到的问题是twilio控制台在每条消息上都会出现11200错误 .
/**
* Dependencies:
* Dotenv, Express, BodyParser, Slack Web Client, Slack Events API
*/
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const createSlackEventAdapter = require('@slack/events-api').createSlackEventAdapter;
//a new export, ErrorCode, is a dictionary of known error types
const { WebClient } = require('@slack/client');
const twilio = require('twilio');
const firebase = require('firebase');
// Creates our express app
const app = express();
// The channel we'll send TalkBot messages to
const channel = 'CBY5883L3';
// The port we'll be using for our Express server
const PORT = 3000;
// Use BodyParser for app
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
/**
* Tokens:
* Slack, Firebase, Twilio
*/
//Retrieve bot token from dotenv file
const bot_token = process.env.SLACK_BOT_TOKEN || '';
// Authorization token
const auth_token = process.env.SLACK_AUTH_TOKEN || '';
// Verification token for Events Adapter
const slackEvents = createSlackEventAdapter(process.env.SLACK_VERIFICATION_TOKEN);
//Slack web client
const web = new WebClient(auth_token);
const bot = new WebClient(bot_token);
//Twilio tokens
const twilio_sid = process.env.TWILIO_SID || '';
const twilio_auth = process.env.TWILIO_AUTH_TOKEN || '';
// Initialize Twilio client using our Twilio SID and Authorization token
const twilioClient = twilio(twilio_sid, twilio_auth);
app.listen(PORT, function (err) {
if (err) {
throw err
}
console.log('Server started on port 3000')
})
// Handles incoming SMS to Twilio number
app.post('/sms', function (req, res) {
const body = req.body.Body
const num = req.body.From
// Sends message to Slack - in format from {
// `res` contains information about the posted message
console.log('Message sent: ', res.ts);
})
.catch(console.error);
}
1 回答
你收到这个错误
因为Twilio需要响应,因为它会向您的
/sms
endpoints 发出POST请求 .响应必须是有效的
TwiML
(XML) .更改您的代码:
对此:
如果不想回复发件人,那么你只需注释掉这一行
// twiml.message('Your SMS was forwarded to Slack...');
我希望这有帮助 .