Choose between Phone number and AlphaNumeric Sender Id when send SMS in Messaging Service - twilio

I added a phone number and an Alphanumeric Sender Id to a Messaging Service.
And my app has a logic to choose between sending by a Phone number or AlphaSenderId.
Could you please provide me API in Messaging Service to have the ability to choose between the Phone number and AlphaSenderId when sending an SMS?

The messaging service will pick the sender automatically based on the country you send the message to. From the doc:
If you add an Alpha Sender to your Twilio Messaging Service, Twilio will select the Alphanumeric Sender ID automatically when you send a message to a supported country, unless you also have a short code number in that same country.
I.e. you cannot influence this manually when you send a message via such an API call:
client.messages
.create({
body: 'Revenge of the Sith was clearly the best of the prequel trilogy.',
from: 'MG9752274e9e519418a7406176694466fa',
to: '+441632960675'
})
.then(message => console.log(message.sid));
But you could do something like this:
const useMS = false;
client.messages
.create({
body: 'Revenge of the Sith was clearly the best of the prequel trilogy.',
from: useMS ? 'MG9752274e9e519418a7406176694466fa' : '+441632960670',
to: '+441632960675'
})
.then(message => console.log(message.sid));

Related

Why can't I programmatically send a templated WhatsApp message using Twilio?

My code:
const client = require('twilio')(accountSid, authToken);
const issueResolution = 'Hi Malcolm, were we able to solve the issue that you were facing?';
client.messages
.create({
from: senderNumber,
body: issueResolution,
to: receiverNumber,
})
.then(message => {
console.log(JSON.stringify(message , null, 2));
});
The body of the message conforms to the "sample_issue_resolution" WhatsApp template shown in the Twilio web console (at https://console.twilio.com/us1/develop/sms/senders/whatsapp-templates).
I can successfully use the above code to send a message to a number which has opted in to my Twilio WhatsApp sandbox. If I try to send a message to another number which has not opted in to the sandbox, there's no error message, but the message is never received. I get the same results when I use one of my custom approved templates. What could be going wrong / how can I debug this?
I'd assume that this message is not matching any of your templates. There could be multiple reasons, such as a different whitespace character or a typo that differentiates both strings.
The Message Log should tell you why a message couldn't be delivered.

Retrieving Message Service Name from Twilio's Phone Numbers API

I'm using the IncomingPhoneNumber resource (https://www.twilio.com/docs/phone-numbers/api/incomingphonenumber-resource) to retrieve infomration about my phone numbers in Twilio.
Both .ReadAsync and .FetchAsync return numbers that I've bought via the Twilio console, and some of those numbers are in a Sender Pool for messaging services.
However, the payload returned by either of those two methods does not contain whether or not a phone number is in a message service pool.
On the console, you can see if a phone number belongs to a message service.
Is it possible, using the IncomingPhoneNumber Resource REST API to find out if a phone number is part of a messaging service?
No, the IncomingPhoneNumber resource won't be able to tell you that. But the PhoneNumber Resource of the Messaging Service API will be able to tell you (or help modify the assignments).
// Download the helper library from https://www.twilio.com/docs/node/install
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.messaging.v1.services('MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
.phoneNumbers
.list({limit: 20})
.then(phoneNumbers => phoneNumbers.forEach(p => console.log(p.sid)));

Twilio give an sms or mms message a called id

Is there a way to make an sms appear with a caller id from a twilio number?
I've found this in the documentation, I've tried it and it does nothing.
"friendlyName"
export function twilioSend() {
client.messages.create({
body: 'hello from node',
to: '+13105551212',
from: '+15625551212',
friendlyName: "my caller ID",
})
.then((message) => console.log(message.sid))
With the above I get the sms and the from number is the from number. In this example 1525551212. I would like it to say from "my caller ID".
Is that even possible?
Here is a list of supported countries for Alphanumeric SenderID.
International support for Alphanumeric Sender ID

Twillio Notify Bulk Sms With Custom Number

I want to send bulk sms using twillio notify in php having a custom text in place of the number ("From") but dont seem to know how to go about it. Am using a messaging service. I would like to show the custom text instead of my sending number when the message is sent. Below is my code for sending the message
<?php
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
$accountSid = "your_account_sid";
$authToken = "your_auth_token";
$serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$client = new Client($accountSid, $authToken);
$recipients = array($num1, $num2, ...); // Your array of phone numbers
$binding = array();
foreach ($recipients as $recipient) {
$binding[] = '{"binding_type":"sms", "address":"+1'.$recipient.'"}'; // +1 is used for US country code. You should use your own country code.
}
$notification = $client
->notify->services($service_sid)
->notifications->create([
"toBinding" => $binding,
"body" => $text
]);
?>
You might be able to send them from Twilio verified phone numbers, but in-general that's not good practice, as your "From" number will get flagged as spam by phone companies
Further than that, you won't be able to change the 'From' attribute, as Twilio doesn't want you fraudulently impersonating other people's phone numbers.
If you can't afford a short code, use a messaging service and buy a bunch of numbers to accommodate your volume.
Twilio developer evangelist here.
When you are using a messaging service, you can setup an alphanumeric sender ID as part of the copilot features for the service. Open up your messaging service settings and add an alphanumeric sender as shown in the screen shot below:

The From phone number is not a valid, SMS-capable inbound phone number

I need to send SMS messages from a website.
I made an account to Twilio and I wanted to try if I really get a message from them.
I use this code that I founded on the net:
const string accountSid = "....";
const string authToken = "....";
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber("+40740539623");
var message = MessageResource.Create(
to,
from: new PhoneNumber("+1402-704-3438"),
body: "This is the ship that made the Kessel Run in fourteen parsecs?");
AccountSid and AuthToken are correct. But I keep getting the error message that the From number is not a valid, SMS-capable inbound phone number or short code for your account.'
I tried to use the number that I have on my Twilio account, I only have a test account, so I thought that I can use this number to send test SMS.
Can you please advise what I'm missing here? How can I send test SMS from Twilio? From Trial Account I can't send messages?
Exception:
pass the phone numbers in as a string in the format "+18001234567", where +1 is the US country code, and whatever after is the 10 digit US phone number.
Also, I have no idea what the +4 area code is you're using in your to number, but you may have a number that doesn't support international SMS. I've only worked with US numbers, both to and from, so can't offer any guidance on how to work with international SMS.

Resources