Mark Rogers
Mark Rogers

Reputation: 97717

How does one programmatically create and assign a static TwiML Bin as an SMS response?

I'm trying to figure out how to programmatically (in C#) create and assigned a TwiML Sms response to incoming sms messages to a phone number. I know how to do this manually by editing the phone number, and I've seen a lot of examples explaining how to do this with a callback url to one's own website. But I just want to be able to assign a TwiML Bin sms response without having to manually configure it and without having to use a callback to emit the message each time. The message will never change so it doesn't make sense to use a callback or a more powerful programmatic feature.

I just want to be able to assign an TwiML bin to a phone number as a sms response programmatically in a similar fashion to how would with the UI. I saw some examples in PHP that show how to create and update a TwiML bin programmatically and I guessing I can assign TwiML bin url to a phone number SMsUrl property. But there are a lot of small blanks in this process. I haven't yet found an example of this in C# and, while there are a lot of TwilMl docs, the docs are largely silent on programmatic TwilMl bin usage.

If I just want to set a fixed text twiML bin response to a twilio phone number I create programmatically in C# how would I do that (without having to host an endpoint)?

If I have to precreate the twiML bin with UI and use its url in a programmatic context as a string, that would be a close second best solution.

Upvotes: 1

Views: 545

Answers (1)

Alan
Alan

Reputation: 10781

A TwiML Bin isn't the best solution since it cannot be programmatically created (so it will be your second best solution).

You can programmatically create a Studio Flow, covered in a recent blog/webinar here, or using the Twilio Functions API (more involved).

That said, if you do use a TwiML bin, you can phones the IncomingPhoneNumber resource to set your Twilio Phone number to point to the URL (Webhook) of your pre-created TwiML Bin programmatically, details are here (look at the update code example in the upper right side and adjust the relevant parameters).

Upvotes: 3

Related Questions