public string SendSMS(string sTwilioPhone, string sToPhone, string Body) { /* * REFERENCE: * https://www.twilio.com/docs/glossary/what-is-a-webhook * https://www.twilio.com/docs/usage/webhooks/sms-webhooks * https://www.twilio.com/docs/usage/webhooks * * DASHBOARD: * Home -> Programmable Messaging * * WEBHOOK: * 1. https://www.twilio.com/console/phone-numbers * 2. choose a Twilio Number * 3. (tab) Messaging > set "CONFIGURE WITH" to "WebHooks" > set WebHook URL */ var fromPhone = new Twilio.Types.PhoneNumber(CleanPhoneNumber(sTwilioPhone)); // https://www.twilio.com/console/phone-numbers var toPhone = new Twilio.Types.PhoneNumber(CleanPhoneNumber(sToPhone)); var message = MessageResource.Create( body: Body, from: fromPhone, to: toPhone ); return(message.Sid); }
static void Main(string[] args) { Console.WriteLine("What number would you like to bombard with calls?"); var outgoing = new Twilio.Types.PhoneNumber("+1" + Console.ReadLine()); Console.WriteLine(); Console.WriteLine("Press ENTER to initiate program."); Console.ReadLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Calling " + outgoing + ". . ."); int count = 1; while (count == 1) { TwilioClient.Init(id, auth); var from = new Twilio.Types.PhoneNumber("(a 'from' phone number)"); var call = Twilio.Rest.Api.V2010.Account.CallResource.Create(outgoing, from, url: new Uri( "http://demo.twilio.com/docs/voice.xml")); System.Threading.Thread.Sleep(5000); } }
/// <inheritdoc /> public async Task <PhoneNumberLookupResult> LookupNumber(string phoneNumber, string countryCode) { if (string.IsNullOrEmpty(countryCode)) { // we default this to US which matches what Twilio will do if it's missing countryCode = "US"; } var twilioPhoneNumber = new Twilio.Types.PhoneNumber(phoneNumber); var twilioOptions = BuildTwilioRequestOptions(countryCode, twilioPhoneNumber); try { var lookupResult = await _twilioWrapper.FetchPhoneNumberResource(twilioOptions, _twilioClient); return(BuildPhoneNumberLookupResult(lookupResult)); } catch { // If we reach here then it's likely that the phone number or country code were not valid // TODO - Logging } return(PhoneNumberLookupResult.FailedLookup); }
public void Send(SmsMessage sms) { TwilioClient.Init(_configuration.AccountSid, _configuration.AuthenticationToken); var pFrom = new Twilio.Types.PhoneNumber(sms.From); var pTo = new Twilio.Types.PhoneNumber(sms.To); var message = MessageResource.Create( body: sms.Body, from: pFrom, to: pTo ); }
public string SendSMS(string sTwilioPhone, string sToPhone, string Body) { var fromPhone = new Twilio.Types.PhoneNumber(sTwilioPhone); // https://www.twilio.com/console/phone-numbers var toPhone = new Twilio.Types.PhoneNumber(sToPhone); var message = MessageResource.Create( body: Body, from: fromPhone, to: toPhone ); return(message.Sid); }
/// <summary> /// This will use the twilio settings to send a test text message. /// </summary> public void Test(string toPhoneNumber, string message = "Hello World!") { _status.Debug("init"); Twilio.TwilioClient.Init(_accountSid, _authToken); var to = new Twilio.Types.PhoneNumber(toPhoneNumber); var fromNum = new Twilio.Types.PhoneNumber(_fromNumber); _status.Debug("sending"); Twilio.Rest.Api.V2010.Account.MessageResource.Create(to, from: fromNum, body: message ); _status.Debug("done"); }
public Task SendAsync(IdentityMessage message) { String accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"]; String authToken = ConfigurationManager.AppSettings["TwilioAuthToken"]; String from = ConfigurationManager.AppSettings["TwilioFrom"]; var toPhone = new Twilio.Types.PhoneNumber(message.Destination); var fromPhone = new Twilio.Types.PhoneNumber(from); Twilio.TwilioClient.Init(accountSid, authToken); String msgBody = message.Body; var msg = MessageResource.Create(to: toPhone, from: fromPhone, body: msgBody); // Plug in your SMS service here to send a text message. return(Task.FromResult(0)); }
public void SendMessages(List <Assignment> assignments) { _status.Debug("Building text messages..."); var dict = this.BuildMessagesToSend(assignments); _status.Debug("Initializing Twilio..."); Twilio.TwilioClient.Init(_accountSid, _authToken); var fromNum = new Twilio.Types.PhoneNumber(_fromNumber); foreach (var kvp in dict) { var to = new Twilio.Types.PhoneNumber(kvp.Key); _status.Debug($"Sending message to {to}..."); Twilio.Rest.Api.V2010.Account.MessageResource.Create(to, from: fromNum, body: kvp.Value ); } }
/// <summary> /// /// <para>BSMSServiceTwilio: Parametered Constructor</para> /// /// <para>Parameters:</para> /// <para><paramref name="_AccountSID"/> Twilio account SID</para /// <para><paramref name="_AuthToken"/> Twilio auth token</para> /// <para><paramref name="_FromPhoneNumber"/> Twilio phone number (sender)</para> /// <para><paramref name="_ErrorMessageAction"/> Error messages will be pushed to this action</para> /// /// </summary> public BSMSServiceTwilio(string _AccountSID, string _AuthToken, string _FromPhoneNumber, Action <string> _ErrorMessageAction = null) { try { /*AccountSID = _AccountSID; * AuthToken = _AuthToken; * * FromPhoneNumber = _FromPhoneNumber;*/ FromPhoneNumber_TwilioType = new Twilio.Types.PhoneNumber(_FromPhoneNumber); TwilioClient.Init(_AccountSID, _AuthToken); bInitializationSucceed = true; } catch (Exception e) { _ErrorMessageAction?.Invoke("BSMSServiceTwilio->Constructor: " + e.Message + ", Trace: " + e.StackTrace); bInitializationSucceed = false; } }
// GET: TextMessage public ActionResult SendSms() { var userId = User.Identity.GetUserId(); Survivor survivor = db.Survivor.FirstOrDefault(s => s.ApplicationId == userId); var accountSid = "AC9e820c12c7a044f14cbb16c10f4222f2"; var authToken = APIInfo.TrilioAuthToken; Twilio.TwilioClient.Init(accountSid, authToken); var to = new Twilio.Types.PhoneNumber(survivor.EmergencyContactNumber); var from = new Twilio.Types.PhoneNumber("+12015089005"); var message = MessageResource.Create( to: to, from: from, body: survivor.FirstName + " has recently experienced a sexual assault. They are letting you know through an application that they need your support. Please contact this person as soon as possible." + survivor.FirstName + " needs you to be emotionally supportive and not ask questions." + survivor.FirstName + " will open up when they are ready." ); return(RedirectToAction("Index", "Survivor")); }
private static async Task <bool> IsTwilioVerified(string num) { bool IsValid = false; var config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); // Find your Account Sid and Token at twilio.com/console. See http://twil.io/secure for more info string accountSid = config["AppSettings:accountSid"]; string authToken = config["AppSettings:authToken"]; try { // Find your Account Sid and Token at twilio.com/console. See http://twil.io/secure for more info TwilioClient.Init(accountSid, authToken); // Reference: https://www.twilio.com/docs/lookup/tutorials/validation-and-formatting var phoneNum = new Twilio.Types.PhoneNumber(num); var numInfo = await PhoneNumberResource.FetchAsync(countryCode : "US", pathPhoneNumber : phoneNum); Console.WriteLine($"Twilio Verified Phone Number: { numInfo.PhoneNumber }"); if (numInfo.PhoneNumber.ToString().Length >= 1) { IsValid = true; } } catch (ApiException e) { Console.WriteLine($"Twilio Error {e.Code} - {e.MoreInfo}"); } catch (Exception ex) { Console.WriteLine("Error:" + ex.Message); throw; } return(IsValid); }
public Task SendAsync(IdentityMessage message) { string twilioSid = ConfigurationManager.AppSettings["TwilioSid"]; string twilioApiKey = ConfigurationManager.AppSettings["TwilioApiKey"]; string twilioFromNr = ConfigurationManager.AppSettings["TwilioFromNr"]; TwilioClient.Init(twilioSid, twilioApiKey); var fromNr = new Twilio.Types.PhoneNumber(twilioFromNr); var toNr = new Twilio.Types.PhoneNumber(message.Destination); var sms = MessageResource.Create( body: message.Body, from: fromNr, to: toNr, pathAccountSid: twilioSid ); Trace.TraceInformation(sms.Status.ToString()); // Twilio doesn't currently have an async API, so we return success. return(Task.FromResult(0)); }
public static async Task <PhoneNumberResource> LookupPhoneNumber(ITwilioRestClient client, string number, CountryCode?countryCode, bool includeCallerName, bool includeCarrier, List <string> addOns, Dictionary <string, object> addOnsData) { var phoneNumber = new Twilio.Types.PhoneNumber(number); var type = new List <string>(); if (includeCallerName) { type.Add("caller_name"); } if (includeCarrier) { type.Add("carrier"); } var options = new FetchPhoneNumberOptions(phoneNumber) { CountryCode = countryCode != null ? $"{countryCode:G}" : null, Type = type, AddOns = addOns, AddOnsData = addOnsData }; return(await PhoneNumberResource.FetchAsync(options, client)); }
public void SendMessage(string message, List <string> attachments) { if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password) && !string.IsNullOrEmpty(_telephone) && _subscribers != null && _subscribers.Count > 0) { TwilioClient.Init(_username, _password); foreach (var subscriber in _subscribers) { var f = new Twilio.Types.PhoneNumber(_telephone); var s = new Twilio.Types.PhoneNumber(subscriber.Telephone); MessageResource header = MessageResource.Create( body: message, mediaUrl: new List <Uri> { new Uri(attachments[0]) }, from: f, to: s); } } }
public void SendAnnouncment(string messageTitle, string messageBody) { var twilioAccountNumber = new Twilio.Types.PhoneNumber(_accountNumber); string formattedMessage = _FormatAnnouncment(messageTitle, messageBody); foreach (string number in _phoneNumbers) { try { string formattedNumber = Regex.Replace(number, "[^0-9]", ""); var message = MessageResource.Create( body: formattedMessage, from: twilioAccountNumber, to: new Twilio.Types.PhoneNumber(formattedNumber) ); Console.WriteLine(message.Sid); } catch (Twilio.Exceptions.ApiException e) { Console.WriteLine(e.Message); } } }
public string SendWhatsapp(string sTwilioPhone, string sToPhone, string Body, List <string> Images = null) { /* * REFERENCE: * https://www.twilio.com/docs/whatsapp/quickstart/csharp * https://www.twilio.com/docs/whatsapp/api * * DASHBOARD: * Home -> Programmable Messaging * * JOIN (SANDBOX): * 1. https://www.twilio.com/console/sms/whatsapp/sandbox * 2. invite users to the sendbox by sending a whatsapp message to your twilio number with the provided code (e.g: "join least-dull") * notes: * we can also use invitation link (whatsapp://send?phone=<TwilioNumber>&text=<Code(URL-Encoded)>) * we can also use QRCode to generate the invitation link * * WEBHOOK (SANDBOX): * 1. https://www.twilio.com/console/sms/whatsapp/sandbox * 2. set a webhook URL in both "WHEN A MESSAGE COMES IN" and\or "STATUS CALLBACK URL" options * * ------------- * * PRODUCTION: * (1) Facebook > Verify your Facebook Business Manager in order to setup WhatsApp Business API using Twilio. * business.facebook > Business settings > Business Information > Business Verification Status * note! if status is not verified > click on "start verification" and follow the instructions * https://business.facebook.com/ * https://business.facebook.com/settings/info * https://business.facebook.com/settings/security * * (2) Twilio > Purchase a new mobile phone number for WhatsApp Business API * https://www.twilio.com/console/phone-numbers/search * * (3) To purchase the phone number, you'll need to submit a regulation-document fit to your country. * https://www.twilio.com/guidelines/regulatory * * (4) Then, you'll have to fill-out an access-request-form and send it to whatsapp team for approval. * note! twilio will contact you within 10 days with the outcome. * https://www.twilio.com/whatsapp/request-access * * to get Facebook Business Id: * FB > Setting > Business Manager * https://business.facebook.com/settings/info * * to approve twilio on facebook bussiness: * FB > Settings > Received > "Approve" Twilio * https://business.facebook.com/settings/requests * * (5) add a new WhatsApp Sender using the approved phone number * https://www.twilio.com/console/sms/whatsapp/senders * * sources: * - https://support.salescandy.com/hc/en-us/articles/360053590431-How-to-apply-and-set-up-WhatsApp-Business-API-number-in-Twilio- * - https://www.twilio.com/docs/whatsapp/tutorial/connect-number-business-profile * - https://www.twilio.com/docs/whatsapp/api * - https://www.twilio.com/docs/whatsapp/tutorial/connect-number-business-profile */ var fromPhone = new Twilio.Types.PhoneNumber($"whatsapp:{CleanPhoneNumber(sTwilioPhone)}"); // https://www.twilio.com/console/phone-numbers var toPhone = new Twilio.Types.PhoneNumber($"whatsapp:{CleanPhoneNumber(sToPhone)}"); var message = MessageResource.Create( body: Body, from: fromPhone, to: toPhone, mediaUrl: Images == null ? null : Images.Select(x => new Uri(x)).ToList() ); return(message.Sid); }
private static FetchPhoneNumberOptions BuildTwilioRequestOptions(string countryCode, Twilio.Types.PhoneNumber twilioPhoneNumber) { var options = new FetchPhoneNumberOptions(twilioPhoneNumber) { CountryCode = countryCode }; options.Type.Add("carrier"); return(options); }