No verification code while registering number via message using twilio trial - c#

Hi I am on trial with twilio.
I have seen this link:
https://www.twilio.com/help/faq/twilio-basics/how-does-twilios-free-trial-work
It says "You must verify a phone number before you can send SMS messages to it from your trial phone number."
And also restricts on the outgoing text
But what if I just want to verfiy the number, using:
var twilio = new TwilioRestClient(
Keys.TwilioSid,
Keys.TwilioToken
);
var result = twilio.SendMessage(
Keys.FromPhone,
message.Destination, message.Body);
// Status is one of Queued, Sending, Sent, Failed or null if the number is not valid
Trace.TraceInformation(result.Status);
// Plug in your SMS service here to send a text message.
return Task.FromResult(0);
I get null when I try to verify the number that are not in the dashboard(web twilio) whereas those with verified from dashboard gets the verification from above code.
Is it intended? I think we need to be able to register at least from web interface?
Error: Account not authorized to call . Perhaps you need to enable some international permissions: twilio.com/user/account/settings/international For Message The number XX is unverified. Trial accounts cannot send messages to unverified numbers; verify xxx at twilio.com/user/account/phone-numbers/verified, or purchase a Twilio number to send messages to unverified numbers

I don't think you can verify a number in the way that you are attempting to do it. Verifying a number adds it to your outgoing numbers. you can look at this page, which provides the full details. https://www.twilio.com/docs/api/rest/outgoing-caller-ids#list-post-example-1
A snippet from the page using the C# Api,
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "{{ sid }}";
string AuthToken = "{{ auth_token }}";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var callerId = twilio.AddOutgoingCallerId("+14158675309", "My Home Phone Number", null, null);
Console.WriteLine(callerId.ValidationCode);
The first argument is the number you would like to verify, and the second argument is simply a friendly name for the number. The above process will initiate a call to the number and ask you to provide the validation code. You will then use the value that is printed to the console and enter that during the validation process, provided that all goes well, once the above process is complete, the number would be verified and you will be able to send an Sms to that number.

Twilio evangelist here.
A trial account has a number of restrictions placed on it, including you can only send SMS messages to verified phone numbers. A verified phone number will show up in your Twilio dashboard under Numbers > Verified Caller IDs:
https://www.twilio.com/user/account/phone-numbers/verified
To verify a number using the .NET helper library, call the AddOutgoingCallerId method like Lewis showed.
Calling this method returns to you a six digit verification code. Twilio will then call the number that you want to verify and ask the person who answers to enter that 6 digit code. If the code entered matches, Twilio adds that phone number as a Verified Caller ID and you an send text messages to it.
Note that while using a Trial account, messages will also be prefixed with the message "Sent from a Twilio Trial account".
If the request to the Twilio REST API made by the AddOutgoingCallerId method fails (wrong credentials, invalid method parameters, etc), you determine this by checking the RestException property:
var result = twilio.AddOutgoingCallerId("+15555555555","Verified Number",null,null);
if (result.RestException!=null) {
Debug.Writeline(result.RestException.Message);
}
Hope that helps.

Related

How to send whatsApp message to any number by using twilio using c#

I am new to Twilio
below is my code to send whatsapp message using C#
static void Main(string[] args)
{
// Find your Account Sid and Token at twilio.com/console
TwilioClient.Init(Model.AccountSid, Model.AuthToken);
var message = MessageResource.Create(
//whatsapp message
to: new PhoneNumber(Model.To), from: new PhoneNumber(Model.From),
body: "Ahoy from Twilio!!!!!"
);
Console.WriteLine("Message SID: " + message.Sid);
}
Model.To have my whatsapp number which I have used while registering with twilio.
Model.From have Twilio's WhatsApp number
if I run this console application then I get message on my whatsapp number
but when I try to send message to my friend's WhatsApp number by assigning that number to Model.To,
I am not getting message on that number
How can I achieve it?
is there any other way to achieve it without twilio?
Thanks in advance.
Did you check the Twilio Debugger for errors. If you are sending the first message from Twilio out to the WhatsApp user, you must initially use a Template, as detailed here.
If you are using the Trial account then
1)first verify that number from here https://www.twilio.com/console/phone-numbers/verified
2)after verifying the number ,send whatsapp message from verified number to the twilio's whatsapp number using your sandbox code (code will be like e.g join XYZ-PQR)
3)after sending the whatsapp message that number will join your sandbox and you will be able to send message on that number

How to call, Hang up, put on hold and unhold calls using Twilio?

I have a Twilio number and I understood that in order to do those 4 actions(Call, Hang up, put onhold and unhold calls) I need to create a conference call, but I don't understand how I add my Twilio number to the conference and how do I add another number of a mobile of a client. For example, if my Twilio number is " +9728888888" and the customer's I want to call to mobile number is "+9725555555" – I want code examples of :
1. Calling the customer(from Twilio number " +9728888888" to mobile number "+9725555555")
2. Hold the call
3. UnHold the cold
4. Hangout the call.
I'm using Twilio NuGet on web api project. Can you give me the code examples , considering the numbers I gave(Twilio and mobile) for all of those four scenarios above? I would really appreciate it.
BTW, I saw the code example on their site:
using Twilio.TwiML;
class Example
{
static void Main()
{
var response = new VoiceResponse();
var dial = new Dial();
dial.Conference("moderated-conference-room",
startConferenceOnEnter: false);
response.Dial(dial);
System.Console.WriteLine(response.ToString());
}
}
but it doesn't acknowledge the Twilio or the mobile phone or even the Twilio authentication so I'm not sure how can it work..
Twilio developer evangelist here.
If you want to make a call from your Twilio number to a end user and put both your agent and the user into a conference call then this is the way that I would do it. I am not, however, a C# developer, so while I'll try to give code samples I'm not experienced in .NET web api projects.
You say that you are using the Twilio package from Nuget, that's a good start.
First up, you need to generate a call to your agent and place them in the conference call to wait for the user. To do this, you would use the Twilio REST API to place the call. That code looks a bit like this
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "your_auth_token";
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber("AGENT_PHONE_NUMBER");
var from = new PhoneNumber("+9728888888");
var call = CallResource.Create(
to,
from,
url: new Uri("http://example.com/conference")
);
When this call connects with the agent's number Twilio will make a request to the URL that is sent to the API. Your application needs to respond to tell Twilio what to do with the call. In this case, we should put the agent into a <Conference> to wait for the user. Within this action we also need to generate a call to the user.
public IHttpActionResult Conference()
{
// make the call to the user
var to = new PhoneNumber("+9725555555");
var from = new PhoneNumber("+9728888888");
var call = CallResource.Create(
to,
from,
url: new Uri("http://example.com/user_conference")
);
// return the TwiML
var response = new VoiceResponse();
var dial = new Dial();
dial.Conference("Conference", endConferenceOnExit: true);
response.Dial(dial);
Ok(response.ToString());
}
Note: I've set the agent side of this conference to endConferenceOnExit: true. This means that when the agent hangs up, the conference call will end for all participants.
Now, Twilio will make the call to the user and when that connects ask the new URL what to do with the call. This time you just need to respond with the TwiML to connect to the same conference. I'll leave that for you to deal with.
Finally, to put participants on hold you need to use the REST API again. You need to get the conference SID and the SID of the participant you want to put on hold. Since you will be putting the user on hold from your agent, you get both of these SIDs in the second webhook callback to your application.
With the conference and call SID, make a POST request like this:
const string conferenceSid = "CONFERENCE_SID";
const string callSid = "CALL_SID";
ParticipantResource.Update(
conferenceSid,
callSid,
hold: true,
holdUrl: new Uri("http://example.com/hold")
);
You can also provide a hold URL which can provide music while the user waits. For more information, check the participant resource documentation. Unholding the user is the same process, but you set hold to false.
Let me know if this gets you on the way to creating this feature.

Twilio not sending SMS

I've tried this code
string AccountSid = "[mySID]";
string AuthToken = "[myAuthCode]";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var me = twilio.SendMessage("+15016536555", "+923355216606", "A blank txt");
Console.WriteLine(me.Sid);
I put my original SID and AuthToken in my code. The me.Sid is giving null.
Moreover, the To number is also registered.
I noted that the To and From in me variable is empty.Their is only send and recieve date and time.
I tried your code and it worked fine when To and From numbers were valid. I could receive the text. However, when I changed the From number it failed and reproduced the same problem. It didn't throw an exception, just failed silently.
Interesting thing is there is a RestException property in the message object which displayed "The From phone number +xxxxxxxxxx is not a valid, SMS-capable inbound phone number or short code for your account." This way it was easy to identify the problem.
I installed Twilio wrapper from NuGet
Install-Package Twilio
and the version I've just tried is 4.0.3
If your version is out of date, update it to the latest version so you can check the error using RestException property.
UPDATE:
The message object and RestException in my application looks like this:

TWILIO cannot send sms from C# console app

I'm having a problem to use TWILIO to send sms from C# console app. Initially I faced an error mentioning "Method not found: 'Void RestSharp.RestClient.set_BaseUrl(System.String)'." After applying solution given in another post the application now runs. However it does not send any sms. After looking at response in another post, I tried using the RestException property and found the following message as exception message "Permission to send an SMS has not been enabled for the region indicated by the 'To' number: +880161xxxxxxx.". So does it mean that Twilio based application cannot work for Bangladesh (+880 country code)? Do you have any plan to update it? However I would like to add mentioning that from the Twilio website I could manage to validate the number(+880161xxxxxxx) by sending verification sms from twilio website.
I tried the following code
using Twilio;
namespace SMSTestApp1
{
class Program
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "xxx";
string AuthToken = "yyy";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage("+1205490xxxx", "+8801615xxxxxx", "Test Message", new string[] { }, String.Empty);
Console.WriteLine(message.Sid);
if (message.RestException != null)
{
Console.WriteLine(message.RestException.Message);
}
Console.WriteLine("Finish");
Console.ReadKey();
}
}
}
I think you need to log into your Twilio portal, click on the top right where your account name is, and select account from that drop down menu. Once that loads, you can select geographic permissions. You will find a list and you will need to enable the country that you are attempting to send too.

Error in sending 2nd text from "twilio rest api"

I am sending messages form my application. But, when sending 2nd text from application, then the message is not sent. I don't know why?
here is the code
for (int i = 0; i <= numbr.Length; i++)
{
var statusurl = "";
var nums = numbr[i];
var delivery = twilioRestClient.SendSmsMessage("+13082242885", nums, msg);
var sq = delivery.Sid;
statusurl = delivery.Uri.ToString();
//store statusurl array to db
}
Help me in getting out of the problem. First message is sent easily and received in very short time.
Answer
the api is not sending 2nd text because i am using twilio Trial account which only allow me to send message to my own verified number
https://www.twilio.com/docs/errors/21608
Twilio Trial accounts send sms to only verified numbers log into your account in twilio portal and verify that number to which you are sending sms. Twilio will call on that number and will ask you type a pin code.
Hope that helps
Twilio evangelist here.
Couple of suggestions.
Check to see if Twilio is returning an error by checking to see if deilvery.RestException is null.
Check the Twilio log in your dashboard to see if Twilio says its sending the second message.
Hope that helps.

Categories