Use TwiMl templates for sending outbound sms - spring-boot

I am new to Twilio. We have a requirement in the project as follow -
Send an outbound SMS to a given number. The message body is static text and should be defined using a template on Twilio(TwiML), so that client can change the message body anytime without making any changes in the backend application.
I have gone through the Twilio documentation to understand how to use TwiML, but couldn't find any document or article which explains how to use TwiML for sending an outbound SMS. Currently I am using following code to send a SMS and the message is configured in the Spring Boot application.properties file.
Message message = Message.creator(new PhoneNumber(phoneNumber),
new PhoneNumber(fromPhoneNumber),
messageBody).setStatusCallback(URI.create(callBackUrl)).create();
Does anyone know how to use TwiML template to send an outbound SMS. Can someone help me to solve this problem. Thank you.

What is Twiml?
Twiml is instructions for Twilio, how to respond to an incoming phone call,SMS, etc...
What is Twiml
It is not for outbound actions.
To initiate an SMS , you should use the Twilio api which is what you are doing when you use the sdk such as Message.creator

Related

In a group chat, should the new message event (websocket) be sent by the client or the API?

I have a doubt, in a group chat system that has a database with a rest API, who should issue the event of a new message?
The client or the endpoint to create the new message?
For example: X user sends a message to group Y, then uses the api endpoint api.com/message-create and that endpoint emits the message-create event through websocket
Example 2: X user sends a message to group Y, then uses the api api.com/message-create endpoint and the endpoint does not emit the message-create event, but was emitted when the user pressed the send message button
I still don't quite understand if it would occupy more websocket channels to achieve that, if a global one is enough, etc.
The server should be responsible for communication logic. So your first example is better.
But: why do you use two communication channels for sending an creating messages?
If you use websocket, you don't need create a message from a client by using additional rest endpoint.
This approach is prone to errors. For example if the client will loose network connection after sending message through websocket and before executing call to the REST endpoint?
The message will not be stored in a database.
Your flow should looks as follows:
User clicks the send button.
Message is send through the websocket.
Message is stored in the database asynchronously (you can do it directly from communication server, or use rest endpoint)
Emit "new message" event to the group.

How do I retrieve the sender number when using Twilio's messaging services with Copilot enabled?

I have a Twilio messaging service with Copilot and the sticky sender feature enabled.
I would like to view the phone number that Copilot assigns to my recipients when I send them a message.
With the Ruby client, I get a MessageContext object when I send a message, but it only has the
messaging service SID - the from method returns nil.
Currently, this is how I'm sending messages:
def send(from, to, message)
client = Twilio::REST::Client.new(ACCOUNT_SID, AUTH_TOKEN)
client.api.account.messages.create(
body: message,
messaging_service_sid: from,
to: to,
status_callback: BASE_URL + '/sms_status/status',
)
end
Twilio developer evangelist here.
I'm not sure, but you might not have the phone number at the time you make the API request using a messaging service. This request really just queues up the message to be sent.
I would check the message object once it has been sent. You have a status callback URL setup, so you should be able to either inspect the parameters sent to that URL or look up the message from the API using its SID and then get the number that was used.

How to pass from and body as parameters in Twilio SMS webhook URL

I have a Twilio SMS number configured to send a request to a WebServer via a Webhook URL. What I am trying to understand is can I pass the 'from' phone number and 'SMS body' as parameters in the Webhook URL?
For example:
https://myserver/v1/sms?phoneNo='FROM'&message='MSG'
I understand I can extract this information from the Body on the server but this would require additional coding, testing, deployment etc... on the web server.
Thanks.
Keep the URL as https://myserver/v1/sms (Twilio will add the parameters for you when it makes the request)
To the right of the webhook url field, change in the drop-down from HTTP POST to HTTP GET
Save
With this configuration, Twilio will send the parameters with its request as URL query parameters.
The names for the two parameters mentioned in your question are
From (The phone number that sent the message) and
Body (The text body of the message.).
Other parameters are: MessageSid, SmsSid, AccountSid, MessagingServiceSid, To, NumMedia
You can read more here: https://www.twilio.com/docs/sms/twiml#twilios-request-to-your-application
If you'd like to have your own names for the GET parameters
then, probably the easiest would be to use Twilio Studio with a HTTP REQUEST widget and configure the phone number with Studio Flow instead of Webhook.
The HTTP REQUEST will let you make a GET request and add your own parameters to it.
For the values you would use {{trigger.message.From}} for your phoneNo and {{trigger.message.Body}} for your message.
You can read more about Twilio Studio's widgets here: https://www.twilio.com/docs/studio/widget-library#http-request

Customize OSB Mail alert body content

I am using Mail as alert-destination in OSB. From proxy service I am calling the alert destination and mail is being sent successfully.
However, the mail content is showing the details of service, destination, timestamp, server name etc details.
I just want to have the payload information in the mail body.
Is therey any way to customize the mail body when adding alert action in a proxy service?
Thanks in advance
The Alert action is very basic, and the email destination isn't really designed to be consumed by humans directly.
You're probably better off alerting to a JMS destination, then dequeuing it using a proxy to transform it into exactly what you want, then route to an SMTP Messaging business service to deliver the email (presumably formatted in HTML).

What can I use as a blank Request URL for Sms?

In order for a number to receive Sms messages, it appears I must enter a value for the Request URL associated with the number. However I do not need to notified of messages in a callback. I'm wondering what value I can put in here that will basically do nothing but still allow me to retrieving messages via the polling mechanism?
Thanks,
Dan
Twilio developer evangelist here.
You can use a URL that responds with an empty <Response> TwiML element. If you don't have a server to host that on, you could use http://twimlets.com. This link ought to do the trick:
http://twimlets.com/echo?Twiml=%3CResponse%3E%3C%2FResponse%3E&

Resources