Twilio awaits response, I don't want server to respond



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am using a Slack webhook to process incoming SMS messages from Twilio. However, the way I have it set up, It seems that Twilio is expecting the web server (slack) to respond to it. This causes errors to be generated in Twilio, and I obviously don't want errors because I'll be getting emails.



I am using the twilio-ruby gem in Ruby to send out the SMS messages, and using the slack-ruby-client to monitor incoming messages from Slack.



How do I stop Twilio from trying to expect a response from the web server when it POSTS to the Slack webhook? Is that even possible or do I have this all configured incorrectly?



EDIT



Here's the function that I have which sends the forwarded SMS to Slack:



const https = require("https");

// Make sure to declare SLACK_WEBHOOK_PATH in your Environment
// variables at
// https://www.twilio.com/console/runtime/functions/configure

exports.handler = (context, event, callback) =>
// Extract the bits of the message we want
const To, From, Body = event;

// Construct a payload for slack's incoming webhooks
const slackBody = JSON.stringify(
text: `!asi SMSnFrom: $FromnMessage: $Body`
);

// Form our request specification
const options =
host: "hooks.slack.com",
port: 443,
path: context.SLACK_WEBHOOK_PATH,
method: "POST",
headers:
"Content-Type": "application/json",
"Content-Length": slackBody.length

;

// send the request
const post = https.request(options, res =>
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);
post.write(slackBody);
post.end();
;









share|improve this question
























  • Why don't you simply acknowledge the POST with a 200 response and be done with it?

    – deceze
    Nov 14 '18 at 5:22











  • Because it's POSTing to slack, not a server that I'm controlling or have access to. I don't think slack allows you to provide responses to incoming webhooks, unless I'm msising something.

    – LewlSauce
    Nov 14 '18 at 5:23











  • It's somewhat bizarre to be accepting HTTP requests without returning a response… But oh well, I have no idea about Slack, so I'll leave you to it…

    – deceze
    Nov 14 '18 at 5:25











  • Yeah that's pretty much how Twilio works with its webhooks. Once it receives a message, it just sends the details to a webhook and waits on a response. Just need to figure out if I can turn off this waiting process.

    – LewlSauce
    Nov 14 '18 at 5:26


















0















I am using a Slack webhook to process incoming SMS messages from Twilio. However, the way I have it set up, It seems that Twilio is expecting the web server (slack) to respond to it. This causes errors to be generated in Twilio, and I obviously don't want errors because I'll be getting emails.



I am using the twilio-ruby gem in Ruby to send out the SMS messages, and using the slack-ruby-client to monitor incoming messages from Slack.



How do I stop Twilio from trying to expect a response from the web server when it POSTS to the Slack webhook? Is that even possible or do I have this all configured incorrectly?



EDIT



Here's the function that I have which sends the forwarded SMS to Slack:



const https = require("https");

// Make sure to declare SLACK_WEBHOOK_PATH in your Environment
// variables at
// https://www.twilio.com/console/runtime/functions/configure

exports.handler = (context, event, callback) =>
// Extract the bits of the message we want
const To, From, Body = event;

// Construct a payload for slack's incoming webhooks
const slackBody = JSON.stringify(
text: `!asi SMSnFrom: $FromnMessage: $Body`
);

// Form our request specification
const options =
host: "hooks.slack.com",
port: 443,
path: context.SLACK_WEBHOOK_PATH,
method: "POST",
headers:
"Content-Type": "application/json",
"Content-Length": slackBody.length

;

// send the request
const post = https.request(options, res =>
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);
post.write(slackBody);
post.end();
;









share|improve this question
























  • Why don't you simply acknowledge the POST with a 200 response and be done with it?

    – deceze
    Nov 14 '18 at 5:22











  • Because it's POSTing to slack, not a server that I'm controlling or have access to. I don't think slack allows you to provide responses to incoming webhooks, unless I'm msising something.

    – LewlSauce
    Nov 14 '18 at 5:23











  • It's somewhat bizarre to be accepting HTTP requests without returning a response… But oh well, I have no idea about Slack, so I'll leave you to it…

    – deceze
    Nov 14 '18 at 5:25











  • Yeah that's pretty much how Twilio works with its webhooks. Once it receives a message, it just sends the details to a webhook and waits on a response. Just need to figure out if I can turn off this waiting process.

    – LewlSauce
    Nov 14 '18 at 5:26














0












0








0








I am using a Slack webhook to process incoming SMS messages from Twilio. However, the way I have it set up, It seems that Twilio is expecting the web server (slack) to respond to it. This causes errors to be generated in Twilio, and I obviously don't want errors because I'll be getting emails.



I am using the twilio-ruby gem in Ruby to send out the SMS messages, and using the slack-ruby-client to monitor incoming messages from Slack.



How do I stop Twilio from trying to expect a response from the web server when it POSTS to the Slack webhook? Is that even possible or do I have this all configured incorrectly?



EDIT



Here's the function that I have which sends the forwarded SMS to Slack:



const https = require("https");

// Make sure to declare SLACK_WEBHOOK_PATH in your Environment
// variables at
// https://www.twilio.com/console/runtime/functions/configure

exports.handler = (context, event, callback) =>
// Extract the bits of the message we want
const To, From, Body = event;

// Construct a payload for slack's incoming webhooks
const slackBody = JSON.stringify(
text: `!asi SMSnFrom: $FromnMessage: $Body`
);

// Form our request specification
const options =
host: "hooks.slack.com",
port: 443,
path: context.SLACK_WEBHOOK_PATH,
method: "POST",
headers:
"Content-Type": "application/json",
"Content-Length": slackBody.length

;

// send the request
const post = https.request(options, res =>
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);
post.write(slackBody);
post.end();
;









share|improve this question
















I am using a Slack webhook to process incoming SMS messages from Twilio. However, the way I have it set up, It seems that Twilio is expecting the web server (slack) to respond to it. This causes errors to be generated in Twilio, and I obviously don't want errors because I'll be getting emails.



I am using the twilio-ruby gem in Ruby to send out the SMS messages, and using the slack-ruby-client to monitor incoming messages from Slack.



How do I stop Twilio from trying to expect a response from the web server when it POSTS to the Slack webhook? Is that even possible or do I have this all configured incorrectly?



EDIT



Here's the function that I have which sends the forwarded SMS to Slack:



const https = require("https");

// Make sure to declare SLACK_WEBHOOK_PATH in your Environment
// variables at
// https://www.twilio.com/console/runtime/functions/configure

exports.handler = (context, event, callback) =>
// Extract the bits of the message we want
const To, From, Body = event;

// Construct a payload for slack's incoming webhooks
const slackBody = JSON.stringify(
text: `!asi SMSnFrom: $FromnMessage: $Body`
);

// Form our request specification
const options =
host: "hooks.slack.com",
port: 443,
path: context.SLACK_WEBHOOK_PATH,
method: "POST",
headers:
"Content-Type": "application/json",
"Content-Length": slackBody.length

;

// send the request
const post = https.request(options, res =>
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);
post.write(slackBody);
post.end();
;






ruby twilio webhooks






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 3:21







LewlSauce

















asked Nov 14 '18 at 5:16









LewlSauceLewlSauce

1,12311226




1,12311226












  • Why don't you simply acknowledge the POST with a 200 response and be done with it?

    – deceze
    Nov 14 '18 at 5:22











  • Because it's POSTing to slack, not a server that I'm controlling or have access to. I don't think slack allows you to provide responses to incoming webhooks, unless I'm msising something.

    – LewlSauce
    Nov 14 '18 at 5:23











  • It's somewhat bizarre to be accepting HTTP requests without returning a response… But oh well, I have no idea about Slack, so I'll leave you to it…

    – deceze
    Nov 14 '18 at 5:25











  • Yeah that's pretty much how Twilio works with its webhooks. Once it receives a message, it just sends the details to a webhook and waits on a response. Just need to figure out if I can turn off this waiting process.

    – LewlSauce
    Nov 14 '18 at 5:26


















  • Why don't you simply acknowledge the POST with a 200 response and be done with it?

    – deceze
    Nov 14 '18 at 5:22











  • Because it's POSTing to slack, not a server that I'm controlling or have access to. I don't think slack allows you to provide responses to incoming webhooks, unless I'm msising something.

    – LewlSauce
    Nov 14 '18 at 5:23











  • It's somewhat bizarre to be accepting HTTP requests without returning a response… But oh well, I have no idea about Slack, so I'll leave you to it…

    – deceze
    Nov 14 '18 at 5:25











  • Yeah that's pretty much how Twilio works with its webhooks. Once it receives a message, it just sends the details to a webhook and waits on a response. Just need to figure out if I can turn off this waiting process.

    – LewlSauce
    Nov 14 '18 at 5:26

















Why don't you simply acknowledge the POST with a 200 response and be done with it?

– deceze
Nov 14 '18 at 5:22





Why don't you simply acknowledge the POST with a 200 response and be done with it?

– deceze
Nov 14 '18 at 5:22













Because it's POSTing to slack, not a server that I'm controlling or have access to. I don't think slack allows you to provide responses to incoming webhooks, unless I'm msising something.

– LewlSauce
Nov 14 '18 at 5:23





Because it's POSTing to slack, not a server that I'm controlling or have access to. I don't think slack allows you to provide responses to incoming webhooks, unless I'm msising something.

– LewlSauce
Nov 14 '18 at 5:23













It's somewhat bizarre to be accepting HTTP requests without returning a response… But oh well, I have no idea about Slack, so I'll leave you to it…

– deceze
Nov 14 '18 at 5:25





It's somewhat bizarre to be accepting HTTP requests without returning a response… But oh well, I have no idea about Slack, so I'll leave you to it…

– deceze
Nov 14 '18 at 5:25













Yeah that's pretty much how Twilio works with its webhooks. Once it receives a message, it just sends the details to a webhook and waits on a response. Just need to figure out if I can turn off this waiting process.

– LewlSauce
Nov 14 '18 at 5:26






Yeah that's pretty much how Twilio works with its webhooks. Once it receives a message, it just sends the details to a webhook and waits on a response. Just need to figure out if I can turn off this waiting process.

– LewlSauce
Nov 14 '18 at 5:26













1 Answer
1






active

oldest

votes


















2














Twilio developer evangelist here.



Twilio is always going to expect at least a 200 response or will timeout at 15 seconds for incoming message webhooks.



You could avoid the error messages by using something in between Twilio and Slack, like Zapier (example in this blog post) or using a Twilio Function (as described here) or with Twilio Studio (from the documentation here).



Hope one of those ideas helps!



Update



Further to my earlier answer, and given the code you used to make the call, I have an update.



When making a request using Node's built in https module you will not get the end event until you have read the data. This is what is causing the timeout between Twilio and the Twilio Function, you are never responding to it because you don't consume the data from the request.



In a quick test I found that just listening for the data event meant that the end event did fire. So update your function to:



 const post = https.request(options, res => 
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("data", () => );
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);


And it should work.






share|improve this answer

























  • Thanks! I'm using a Twilio function to send to slack, just as mentioned in that article, but that's what's generating the error. I guess I need to figure out how to make more changes to the function.

    – LewlSauce
    Nov 16 '18 at 2:23












  • Hmm, can you share the code you're using in your function. I reckon there might be something there that's not behaving.

    – philnash
    Nov 16 '18 at 3:19











  • absolutely. Updated the original post to reflect the function.

    – LewlSauce
    Nov 16 '18 at 3:21











  • Think I found what was going on, I updated my answer.

    – philnash
    Nov 16 '18 at 4:37











  • Nice! Thanks so much! That did the trick. No errors :)

    – LewlSauce
    Nov 18 '18 at 5:17











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293589%2ftwilio-awaits-response-i-dont-want-server-to-respond%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Twilio developer evangelist here.



Twilio is always going to expect at least a 200 response or will timeout at 15 seconds for incoming message webhooks.



You could avoid the error messages by using something in between Twilio and Slack, like Zapier (example in this blog post) or using a Twilio Function (as described here) or with Twilio Studio (from the documentation here).



Hope one of those ideas helps!



Update



Further to my earlier answer, and given the code you used to make the call, I have an update.



When making a request using Node's built in https module you will not get the end event until you have read the data. This is what is causing the timeout between Twilio and the Twilio Function, you are never responding to it because you don't consume the data from the request.



In a quick test I found that just listening for the data event meant that the end event did fire. So update your function to:



 const post = https.request(options, res => 
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("data", () => );
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);


And it should work.






share|improve this answer

























  • Thanks! I'm using a Twilio function to send to slack, just as mentioned in that article, but that's what's generating the error. I guess I need to figure out how to make more changes to the function.

    – LewlSauce
    Nov 16 '18 at 2:23












  • Hmm, can you share the code you're using in your function. I reckon there might be something there that's not behaving.

    – philnash
    Nov 16 '18 at 3:19











  • absolutely. Updated the original post to reflect the function.

    – LewlSauce
    Nov 16 '18 at 3:21











  • Think I found what was going on, I updated my answer.

    – philnash
    Nov 16 '18 at 4:37











  • Nice! Thanks so much! That did the trick. No errors :)

    – LewlSauce
    Nov 18 '18 at 5:17















2














Twilio developer evangelist here.



Twilio is always going to expect at least a 200 response or will timeout at 15 seconds for incoming message webhooks.



You could avoid the error messages by using something in between Twilio and Slack, like Zapier (example in this blog post) or using a Twilio Function (as described here) or with Twilio Studio (from the documentation here).



Hope one of those ideas helps!



Update



Further to my earlier answer, and given the code you used to make the call, I have an update.



When making a request using Node's built in https module you will not get the end event until you have read the data. This is what is causing the timeout between Twilio and the Twilio Function, you are never responding to it because you don't consume the data from the request.



In a quick test I found that just listening for the data event meant that the end event did fire. So update your function to:



 const post = https.request(options, res => 
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("data", () => );
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);


And it should work.






share|improve this answer

























  • Thanks! I'm using a Twilio function to send to slack, just as mentioned in that article, but that's what's generating the error. I guess I need to figure out how to make more changes to the function.

    – LewlSauce
    Nov 16 '18 at 2:23












  • Hmm, can you share the code you're using in your function. I reckon there might be something there that's not behaving.

    – philnash
    Nov 16 '18 at 3:19











  • absolutely. Updated the original post to reflect the function.

    – LewlSauce
    Nov 16 '18 at 3:21











  • Think I found what was going on, I updated my answer.

    – philnash
    Nov 16 '18 at 4:37











  • Nice! Thanks so much! That did the trick. No errors :)

    – LewlSauce
    Nov 18 '18 at 5:17













2












2








2







Twilio developer evangelist here.



Twilio is always going to expect at least a 200 response or will timeout at 15 seconds for incoming message webhooks.



You could avoid the error messages by using something in between Twilio and Slack, like Zapier (example in this blog post) or using a Twilio Function (as described here) or with Twilio Studio (from the documentation here).



Hope one of those ideas helps!



Update



Further to my earlier answer, and given the code you used to make the call, I have an update.



When making a request using Node's built in https module you will not get the end event until you have read the data. This is what is causing the timeout between Twilio and the Twilio Function, you are never responding to it because you don't consume the data from the request.



In a quick test I found that just listening for the data event meant that the end event did fire. So update your function to:



 const post = https.request(options, res => 
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("data", () => );
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);


And it should work.






share|improve this answer















Twilio developer evangelist here.



Twilio is always going to expect at least a 200 response or will timeout at 15 seconds for incoming message webhooks.



You could avoid the error messages by using something in between Twilio and Slack, like Zapier (example in this blog post) or using a Twilio Function (as described here) or with Twilio Studio (from the documentation here).



Hope one of those ideas helps!



Update



Further to my earlier answer, and given the code you used to make the call, I have an update.



When making a request using Node's built in https module you will not get the end event until you have read the data. This is what is causing the timeout between Twilio and the Twilio Function, you are never responding to it because you don't consume the data from the request.



In a quick test I found that just listening for the data event meant that the end event did fire. So update your function to:



 const post = https.request(options, res => 
// only respond once we're done, or Twilio's functions
// may kill our execution before we finish.
res.on("data", () => );
res.on("end", () =>
// respond with an empty message
callback(null, new Twilio.twiml.MessagingResponse());
);
);


And it should work.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 4:37

























answered Nov 14 '18 at 7:02









philnashphilnash

39.3k93554




39.3k93554












  • Thanks! I'm using a Twilio function to send to slack, just as mentioned in that article, but that's what's generating the error. I guess I need to figure out how to make more changes to the function.

    – LewlSauce
    Nov 16 '18 at 2:23












  • Hmm, can you share the code you're using in your function. I reckon there might be something there that's not behaving.

    – philnash
    Nov 16 '18 at 3:19











  • absolutely. Updated the original post to reflect the function.

    – LewlSauce
    Nov 16 '18 at 3:21











  • Think I found what was going on, I updated my answer.

    – philnash
    Nov 16 '18 at 4:37











  • Nice! Thanks so much! That did the trick. No errors :)

    – LewlSauce
    Nov 18 '18 at 5:17

















  • Thanks! I'm using a Twilio function to send to slack, just as mentioned in that article, but that's what's generating the error. I guess I need to figure out how to make more changes to the function.

    – LewlSauce
    Nov 16 '18 at 2:23












  • Hmm, can you share the code you're using in your function. I reckon there might be something there that's not behaving.

    – philnash
    Nov 16 '18 at 3:19











  • absolutely. Updated the original post to reflect the function.

    – LewlSauce
    Nov 16 '18 at 3:21











  • Think I found what was going on, I updated my answer.

    – philnash
    Nov 16 '18 at 4:37











  • Nice! Thanks so much! That did the trick. No errors :)

    – LewlSauce
    Nov 18 '18 at 5:17
















Thanks! I'm using a Twilio function to send to slack, just as mentioned in that article, but that's what's generating the error. I guess I need to figure out how to make more changes to the function.

– LewlSauce
Nov 16 '18 at 2:23






Thanks! I'm using a Twilio function to send to slack, just as mentioned in that article, but that's what's generating the error. I guess I need to figure out how to make more changes to the function.

– LewlSauce
Nov 16 '18 at 2:23














Hmm, can you share the code you're using in your function. I reckon there might be something there that's not behaving.

– philnash
Nov 16 '18 at 3:19





Hmm, can you share the code you're using in your function. I reckon there might be something there that's not behaving.

– philnash
Nov 16 '18 at 3:19













absolutely. Updated the original post to reflect the function.

– LewlSauce
Nov 16 '18 at 3:21





absolutely. Updated the original post to reflect the function.

– LewlSauce
Nov 16 '18 at 3:21













Think I found what was going on, I updated my answer.

– philnash
Nov 16 '18 at 4:37





Think I found what was going on, I updated my answer.

– philnash
Nov 16 '18 at 4:37













Nice! Thanks so much! That did the trick. No errors :)

– LewlSauce
Nov 18 '18 at 5:17





Nice! Thanks so much! That did the trick. No errors :)

– LewlSauce
Nov 18 '18 at 5:17



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293589%2ftwilio-awaits-response-i-dont-want-server-to-respond%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)