I am trying make phonecall via Twilio using c# i am using the below code to make call.code executes successfully but i wont receive call.In my twilio page it shows staus as completed and durations.
const string accountSid = "ACe200aeb6115e1f3038a012e1103bd874";
const string authToken = "6XXXXXX";
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber("+12025688652");
var from = new PhoneNumber("+919500553163");
var call = CallResource.Create(to,
from,
url: new Uri("https://demo.twilio.com/welcome/voice/"));
Console.WriteLine(call.Sid);
Twilio developer evangelist here.
I believe that you are actually making that call successfully. You are not experiencing the call yourself because of the parameters you have used.
You are making the call from your verified number. This is your real phone number, but when you set it to be the from address that just means Twilio will use it as the caller ID for the call.
For the to address you are using your Twilio number that you have bought within your account. When you make calls to that number, Twilio makes a webhook (HTTP) request to the URL that is set as the voice response in the number's settings. Currently, that is still set to the default, so Twilio retrieves this URL: https://demo.twilio.com/welcome/voice/. If you click through, you will see that this just reads out a message.
The URL you use when you create the call is also the default URL.
So what is happening with the call is that Twilio is using your caller ID to dial your Twilio number and when the call is answered, both sides of the call are reading out that message to each other.
If you want to at least make your own phone ring, then I'd start by reversing the to and from numbers in your API call. If you do that, then you should receive a call on your phone and when you answer it you will hear the demo message. Then, once you've done that you can start writing your own TwiML responses, possibly using Twimlbins to get started or by building your own application.
Let me know if this helps.
Related
I recently upgraded the Twilio C# DLL we've been using to handle SMS messages. We are now on Twilio.DLL v5.16.2. I have a webhook set up to call a custom URL on our website. That part is working, because I can log the Request coming in (message SID and body and all that good stuff). At the end, we have code to instantiate a MessagingResponse object to send back a confirmation that the message was received. That's not working anymore. I don't get a SMS message on my phone nor do I see an Outgoing API record on the SMS logs page when I'm logged into my project on Twilio.com (whereas I do see the test message I've sent to our number as an Incoming message).
There is no error or exception either.
Any idea how to debug/solve this?
string responseTxt = "TESTING: Got it. Thanks.";
var smsResponse = new MessagingResponse();
var smsMsg = smsResponse.Message(responseTxt);
response.Write(smsMsg);
Twilio developer evangelist here.
I'm not a C# developer, so forgive me if I'm wrong. Also, I don't know what happened with this change.
Anyway, from what I can see, the message body when using the MessagingResponse's Message method appears to be a named argument now. Changing your code to the following should work for the latest version of the DLL.
var smsMsg = smsResponse.Message(body: responseTxt);
Let me know if that helps.
I'm not sure there's much to update as the exact same scenario still stands. But I can reiterate to see if this provides any additional clues.
We have a Twilio SMS service set up. There is a webhook assigned to our number that maps to an HTTP Handler on an ASP.NET website. The code in the handler logs in our database the fact that an SMS message was received and various bits of info (from the Request.Form variables supplied by Twilio, From number, body of the message, num of media, etc.).
Then, the code "replies" to the original SMS sender using the MessagingResponse object. See original code snippet. Really couldn't be much simpler.
Note, this is and has all been working quite well, using the Twilio c# helper library 5.6.
I upgraded the Twilio library to the latest rev (5.25.1) and its dependencies. Copied the new DLLs to our dev webserver. Now the reply message, using the MessagingResponse object, never occurs. The webhook is still called as I can see the new record in the database logging the message details. Just no response. No error, no exception. Just nothing.
If I rollback to our old version of the Twilio library (and its dependencies, thank goodness for Git!), it works again.
The docs say that the from can be a phone number OR client
https://www.twilio.com/docs/api/voice/making-calls
From: The phone number or client identifier to use as the caller id. If
using a phone number, it must be a Twilio number or a Verified
outgoing caller id for your account.
however - the c# sdk doesnt seem to support the from being a Client - anyway to use a client instead of a phone number? using twilio voice SDK for ios and trying to allow the call receiver to see it as a "missed call" so they can call back.
Twilio evangelist here.
The helper library asks for an IEndpoint as the to parameter. There are a two classes that implement IEndpoint: PhoneNumber, Client.
var to = new Client("Bob");
var from = new PhoneNumber("+15017250604");
var call = CallResource.Create(to,
from,
url: new Uri("http://demo.twilio.com/docs/voice.xml"));
Hope that helps.
When i send a text to a customer using a messaging service id. The from number is null in the returned MessageResource. Code below.
Is the only way to determine the From by making an additional call out using the message sid? I need the from used for analytics and so I can use the same number to contact an account in case the customer uses multiple contact numbers.
return await MessageResource.CreateAsync
(
to: new PhoneNumber(toNumber),
messagingServiceSid: messengerSid,
body: message
);
Twilio developer evangelist here.
When you use a messaging service to send messages from various numbers then you cannot know at the time of message creation what the number used will be. When you make the request to send the message, Twilio queues that message up to be delivered by the messaging service. If you inspect the status of the message object you receive from the API call you show in your question you will see it is "accepted". At this point the messaging service won't have decided which number to use.
So, you can either make a second request to the API using the message SID that is returned to find out the From number. Or, you could set a StatusCallback URL which would receive a request once the message was sent, including the From number.
Let me know if that helps at all.
I can not seem to find any documentation on the Twilio site about this. But we are using C# to find the body text of a responder.
We want to be able to get the incoming text message body and then send the user a message back if the phrase the send to us contains or matches the phrase we want.
Example:
User sends "Sweepstakes" to our number
We SMS response "Congratulations, please go to our desk to retrieve your prize. Code 2222"
Is there a way to get the user's body text from the SMS and send them a specific response back. If so how?
Twilio evangelist here.
All you need to do is have the URL that you have set as your Twilio phone numbers SMS Request URL return some TwiML that looks like this:
<Response>
<Sms>
Congratulations, please go to our desk to retrieve your prize. Code 2222
</Sms>
</Response>
The SMS TwiML verb will automatically bounce back the message to the number that sent the SMS. You can either generate this XML yourself or you can use the Twilio .NET TwiML generator to do it for you. (You can get the generator with the twilio-csharp project, or better yet install it as a NuGet package.)
If you want to access the incoming SMS messages body, Twilio sends it along with a bunch of other parameters as form data (http://www.twilio.com/docs/api/twiml/sms/twilio_request). It looks like you might be using an HTTP Handler to handle the requests Twilio is making when and SMS is sent to your Twilio number. If that is the case, you can get those values inside of the ProcessRequest method.
If you Twilio is making its request as a GET:
string body = context.Current.Request.Querystring["body"]
Or if Twilio is making its request as a POST:
string body = context.Current.Request.Form["body"]
Hope that helps.
Devin
This question relates to Twilio and the API for it (C#).
I do not have a website nor a web application, just a need to send SMS notifications to my own private mobile when something happens on a server (NOT a webserver). I have already, successfully, sent SMS to my mobile from a C# dll. I want to check the status of the message. All the references imply website/web application use cases, and getting the status using a URL.
How do I do this in C#? Is there an example of the suggestion made here? No PHP or other web servery technology.
The solution I found, was ridiculously simple. The suggestion (made here) was to hang on to the message id. I discovered the GetSMSMessage method on TwilioRestClient. So querying message status some time after sending will give you the updated status.
By the way, the one thing you'll want to watch out for is that if you query the API too soon, you might get a status of "queued" or "sending" rather than "sent" or "failed", so be sure that your logic is set up to handle these other possible responses.
Also good to keep in mind that if you try to send more than 1 message per-second via a Twilio phone number, Twilio will queue the excess messages and release them at a rate of 1 message per-second per-number. This comes into play because if you have a burst where you send 10 messages in 1 second, but then you go to retrieve the status of the messages after 5 seconds half of the messages will be "sent" and half will be "queued".
If you dont have a callback url. Just call the method
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
body: "Join Earth's mightiest heroes. Like Kevin Bacon.",
from: new Twilio.Types.PhoneNumber(fromNumber),
to: new Twilio.Types.PhoneNumber(toNumber)
);
Console.WriteLine(message.Sid);
//Get the status from twilio
TwilioClient.Init(accountSid, authToken);
var verificationCheck = MessageResource.Fetch(message.Sid);
Console.WriteLine(verificationCheck.Status);
where Sid is the id you get back from Twilio.