TWILIO cannot send sms from C# console app - c#

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.

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 do I send a notification to a user in Teams via the Bot Framework?

I have a Bot created with v4 of the Microsoft Bot Framework. I can successfully use this bot in the "Test in Web Chat" portion in the Azure Portal. I can also successfully use this bot in an app that I've created in Microsoft Teams. I now want to send a notification from the "Test in Web Chat" piece to a specific user in Teams. For example, in the "Test in Web Chat" piece, I'd like to enter
Hello someuser#mytenant.com
When this is sent via the "Test in Web Chat" piece, I'd like to show "Hello" in Microsoft Teams to only someuser#mytenant.com. I have successfully tokenized the string from the "Test in Web Chat". Thus, I know what I want to send, and who I want to send it to. However, I do not know how to actually send it.
Currently, I have the following in my bot:
public class EchoBot : ActivityHandler
{
private ConcurrentDictionary<string, ConversationReference> _conversationReferences;
public EchoBot(ConcurrentDictionary<string, ConversationReference> conversationReferences)
{
_conversationReferences = conversationReferencs;
}
private void AddConversationReference(Activity activity)
{
var reference = activity.GetConversationReference();
_conversationReferences.AddOrUpdate(reference.User.Id, reference, (key, newValue) => reference);
}
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> context, CancellationToken cancellationToken)
{
AddConversationReference(context.Activity as Activity);
var parameters = GetParameters(); // Parses context.Activity.Text;
// Send a message to the target (i.e. someuser#mytenant.com)
var connection = new Microsoft.Bot.Connector.ConnectorClient(new Uri(context.Activity.ServiceUrl));
var tenant = context.Activity.GetChannelData<TeamsChannelData>().Tenant;
// how do I send the message to parameters.Target?
// Confirm message was sent to the sender
var confirmation = $"Message was sent to {parameters.Target}.";
await context.SendActivityAsync(MessageFactory.Text(confirmation));
}
}
I've reviewed how to send proactive notifications to users. However, I've been unsuccessful in a) getting the user specified in parameters.Target and b) sending a notification to that user. What am I missing?
First, you'll need to map user#email.com to their Teams userId (maybe with a static dictionary), which is in the format of:
29:1I9Is_Sx0O-Iy2rQ7Xz1lcaPKlO9eqmBRTBuW6XzXXXXXXXXMij8BVMdBcL9L_RwWNJyAHFQb0TXXXXXX
You can get the Teams UserId by either:
Querying the roster, or
Having the user message the bot, and setting a breakpoint on an incoming message, looking at the Activity.ChannelData for the Teams userId, or
Dynamically build a static dictionary of all incoming messages that stores the user's email mapped to their Teams userId (I believe both are found in Activity.ChannelData).
Note: #1 and #2 both require a user to message the bot, first, which sort of defeats the purpose of proactive messages
After you have the appropriate Teams IDs, you just send a proactive message to a Teams user. The end of this link also mentions trustServiceUrl, which you may find handy if you run into permissions/auth issues when trying to send a proactive message.

No verification code while registering number via message using twilio trial

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.

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.

Making telephone call from ASP.NET application

I have a requirement that we need to make a telephone call using ASP.NET application.
Our ASP.NET application is used in call center. Currently, they make a call to customer manually. Now, the call should go from our application by clicking the phone number link and starts recording the conversation between the agent (application user) and customer.
What all would be the hardware requirements for the above scenario?
How can we implement telephone calling in asp.net application and what are the required components to implement the same?
Nexmo offers a range of cloud communication APIs including Voice API that allows you to fulfil this requirement.
All you need is to install the Nuget package:
Install-Package Nexmo.Csharp.Client
Then use the Call class:
Call.Do(new Call.CallCommand
{
to = new[]
{
new Call.Endpoint
{
type = "phone",
number = NEXMO_TO_NUMBER
}
from = new Call.Endpoint
{
type = "phone",
number = NEXMO_FROM_NUMBER
},
answer_url = new[]
{
NEXMO_CALL_ANSWER_URL
}
});
Here's a detailed post on how to make a phone call with Nexmo Voice API and ASP.Net
If you want to use phone line you should use Computer-telephony boards, for example Dialogic: http://www.dialogic.com/products/ip_enabled/ip_boards.htm They should have API, so you will be able to use it from your application.
In addition to Asterisk, you might also consider Twilio, a web based telephony service that provides you a rest based api for making and receiving phone calls. See http://www.twilio.com/docs/howto/ for info.
You Can Use Third party API To Make a Call Using Asp.net Code.First You Need To Register. Here's a detailed post on
How To Make a Call Using Asp.net Code
protected void btnCall_click(object sender, EventArgs e)
{
// Call porcessing happens here.
// Use your account SID and authentication token instead of
// the placeholders shown here.
var accountSID = "C0d09f4042d1ff4acb55329cf8e5efb";
var authToken = "05b278c6f3538d3a35f13b25c73dff";
// Instantiate an instance of the Twilio client.
TwilioClient.Init(accountSID, authToken);
// Retrieve the account, used later to retrieve the
var account = AccountResource.Fetch(accountSID);
// this.varDisplay.Items.Clear();
// Retrieve the values entered by the user.
var To =new PhoneNumber(txtMobileNumber.Text);
//twlio=14155992671
var from = new PhoneNumber("+918098641075");
var myMessage = this.txtMessage.Text;
// Create a URL using the Twilio message and the user-entered
// text. You must replace spaces in the user's text with '%20'
// to make the text suitable for a URL.
var url = #"http://twimlets.com/message?Message%5B0%5D={myMessage.Replace()}";
var twimlUri = new Uri(url);
// Display the endpoint, API version, and the URL for the message.
this.varDisplay.Items.Add(#"Using Twilio endpoint { }");
this.varDisplay.Items.Add(#"Twilioclient API Version is {apiVersion}");
this.varDisplay.Items.Add(#"The URL is {url}");
// Place the call.
var Call=CallResource.Create(To,from,url:twimlUri);
// var call = CallResource.create(to, from, url: twimlUri);
this.varDisplay.Items.Add("Call status: " + Call.Status);
}

Categories