Brian Cook
Brian Cook

Reputation: 11

Getting error 11200 on every sms message that posts to slack

im trying to send sms message to slack, i have it where the message is posted. the problem im having is that the twilio console gives a 11200 error on every message.


    /**
     * 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);
      }

Upvotes: 1

Views: 1181

Answers (1)

Alex Baban
Alex Baban

Reputation: 11692

You get this error

Error - 11200 HTTP retrieval failure

because Twilio expects a response as it makes the POST request to your /sms endpoint.

The response needs to be a valid TwiML (XML).

Change your code:

// 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);
  }

to this:

// 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

    const twiml = new twilio.twiml.MessagingResponse();
    twiml.message('Your SMS was forwarded to Slack...');
    res.writeHead(200, { 'Content-Type': 'text/xml' });
    res.end(twiml.toString());

  });

If don't want to respond to the sender then you just comment out this line
// twiml.message('Your SMS was forwarded to Slack...');


I hope this helps.

Upvotes: 0

Related Questions