I searched through all the documentation of Twilio. All I found is getting started with Alphanumeric-Sender-ID: https://support.twilio.com/hc/en-us/articles/223181348-Getting-Started-with-Alphanumeric-Sender-ID-for-Twilio-Programmable-SMS and articles like this.
No any of the link explaining about where I can add it. Please guide.
Twilio developer evangelist here.
Once your account has alphanumeric sender IDs enabled, as described in the article you linked to, you can use them in one of two ways.
Either you set your alphanumeric sender ID as the From parameter when sending a message using the messages resource. This is explained in a bit more depth in this article about changing the sender ID for SMS messages or in this blog post I wrote about sending messages with alphanumeric sender IDs.
Or, you can create yourself a messaging service with Copilot and setup the alphanumeric sender ID there. This has the benefit of allowing you to setup a number pool to fall back on for sending to countries that don't support alphanumeric sender IDs, like the US.
From your Stack Overflow account it looks like you mainly program PHP for your back end. Here's a quick example:
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/console
$sid = "your_account_sid";
$token = "your_auth_token";
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create($toNumber,
array(
"body" => "This is a branded message",
"from" => "ALPHA"
)
);
Let me know if that helps at all.
Related
I use the credentials that Twilio provides me in the dashboard:
Checking that they are the live credentials:
I also check that the number I want to use is the one that is confirmed in sandbox.
I have the following code snippet:
$twilio_number = "+51XXXXXX618";
$client = new \Twilio\Rest\Client(
'account_sid',
'auth_token'
);
$message = $client->messages->create(
"whatsapp:+51XXXXXX148",
[
// "from" => "whatsapp:+14155238886",
"from" => "whatsapp:".$twilio_number,
"body" => "Prueba de envio de msj"
]
);
And I get the following error (code in php):
Twilio developer evangelist here.
In your code you appear to be trying to send a message from the number that starts +51.
That number is a participant in your sandbox, but that means you can send messages to that number, not from it. When you are using the Twilio WhatsApp sandbox you can only send messages from your sandbox number, the one starting +1415.
To move on from the sandbox, you need to follow these instructions to register a number with WhatsApp that you can use for your business.
How can I get a conference participant's phone number using the Twilio API? I am using the official Twilio PHP Library.
Hello Twilio Developer Evangelist here. 👋
What you can do is to fetch all active participants with a snippet like this (you can find more details in the docs for the conference participants.
<?php
// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;
// Find your Account Sid and Auth Token at twilio.com/console
// DANGER! This is insecure. See http://twil.io/secure
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$twilio = new Client($sid, $token);
$participants = $twilio->conferences("CFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
->participants
->read(array(), 20);
foreach ($participants as $record) {
print($record->callSid);
// "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
Now, when you did this you'll see that the participant record does not include the phone number of the participant. But what it includes is the call_sid. The call sid helps you to identify the caller and retrieve call details.
There you have two options (I described something similar just recently here).
1. Persist the call information when you route callers into the conference
What you could do when you route people into the conference is to persist their numbers and call sids in your application. This way you could have a registry with all the people that entered your conference and access their phone numbers quickly when you need them.
2. Make another API call to get the call details and caller number
When you have the call SID what you can always do is to fetch the call details one by one.
<?php
$call = $twilio->calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
->fetch();
print($call->from);
The first approach saves you API calls with the cost of maintaining your own persistence layer. The second approach makes more API calls but it is easier to set up.
As always, it depends on the situation.
I hope that helps. :)
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:
I would like to make my client to check whether end client is received text or not and what reply he/she has sent? I always going through twilio to see whether client received sms or not? Is there any way to check it from twilio?
Twilio developer evangelist here.
You can get both incoming messages to your Twilio numbers and reports on the status of messages after you send them from Twilio using webhooks.
When you send a message you can include a StatusCallback parameter. The parameter should be a URL in your application.
$client->messages
->create(
$to,
array(
"from" => $from,
"body" => "Let's grab lunch at Milliways tomorrow!",
"statusCallback" => "https://example.com/messageStatus"
)
);
Twilio will send a POST request to the statusCallback URL each time your message status changes to one of the following: queued, failed, sent, delivered, or undelivered. It will include the original message's SID, so you can tie these webhooks back to the message you sent.
Similarly, you can get these webhook notifications for incoming messages to your Twilio numbers. For this you need to set up the incoming webhook URL to the number in your Twilio console. Set it to a URL in your application and you will receive a webhook when someone sends a message to your Twilio number. Check out this quickstart guide on receiving messages to your Twilio number with PHP.
Let me know if that helps at all.
[edit]
Thanks for the comment where you made it clear that this is after the fact, not at the time of sending.
In this case, you can absolutely list the messages by the phone number that sent them. A message resource includes a Status attribute that lists the current message state in the Twilio system, anything from "accepted" and "queued" to "sending", "sent", "delivered", "undelivered" and "failed". You can see more about these statuses in the documentation.
To get the list of messages sent from a number you can use the following code:
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);
// Loop over the list of messages and echo a property for each one
foreach ($client->messages->read(array("from" => $FROM_NUMBER) as $message) {
echo $message->status . " - " . $message->to . " = " . $message->body;
}
You can pull data for specific messages https://www.twilio.com/docs/api/messaging/message#delivery-related-errors
or you can simply pull all the logs
I am using Twilio service to send messages to different types of users in my application. Now the message logs show all messages listing properly, but can I add an optional parameter to identify a different set of messages sent to different users.
Is user Custom parameters allowed with Twilio message logs to identify/filter Messages based on this parameter?
If my way of thinking is wrong, is there any solution to categorize or identify a specific group of messages sent to a particular group of people?
for ($i = 0; $i < count($mobile_numbers); $i++)
{
$mobile_number = $mobile_numbers[$i];
$otp_message_result = json_decode(send_text_message($mobile_number, $custom_message));
$msg_sid = $otp_message_result -> sid;
$msg_status = $otp_message_result -> status;
}
Twilio developer evangelist here.
There are no custom fields available within the Twilio API for saving your own data to.
If you want to find all the messages sent to one telephone number then you can filter by that number, like this:
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "your_account_sid";
$token = "your_auth_token";
$client = new Client($sid, $token);
$phone_number = PHONE_NUMBER;
// Loop over the list of messages and echo a property for each one
foreach ($client->messages->read(array("To" => $phone_number)) as $message) {
echo $message->body;
}
If you need to be any more specific, then I recommend you save the SIDs of the messages that you sent to each user to your own database.