本文整理汇总了C#中Twilio.TwilioRestClient类的典型用法代码示例。如果您正苦于以下问题:C# TwilioRestClient类的具体用法?C# TwilioRestClient怎么用?C# TwilioRestClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TwilioRestClient类属于Twilio命名空间,在下文中一共展示了TwilioRestClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendSms
public static Twilio.Message SendSms(string number, string content)
{
var formattedNumber = FormatPhoneNumber(number);
var restClient = new TwilioRestClient(_config.GetString(ACCOUNT_SID_KEY), _config.GetString(AUTH_TOKEN_KEY));
return restClient.SendMessage(_config.GetString(PHONE_NUMBER_KEY), formattedNumber, content);
}
示例2: SendMessage
private bool SendMessage(string toNumber,string textMsg)
{
try
{
string AccountSid = "AC04b7185526614dcdfcd8e03e0a5842a2";
string AuthToken = "976054e44e21b91c4af357f770f325fc";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
SMSMessage result = twilio.SendSmsMessage("+16782937535", toNumber, textMsg);
if (result.RestException != null)
{
//an exception occurred making the REST call
string message = result.RestException.Message;
}
return true;
}
catch (Exception)
{
return false;
}
// Find your Account Sid and Auth Token at twilio.com/user/account
}
示例3: TwilioSMSService
public TwilioSMSService(IOptions<SmsSettings> smsSettings)
{
_smsSettings = smsSettings.Value;
//TwilioClient.Init(_smsSettings.Sid, _smsSettings.Token);
_restClient = new TwilioRestClient(_smsSettings.Sid, _smsSettings.Token);
}
示例4: SendSmsMessage
private void SendSmsMessage(string username, MessageObject messageObj)
{
const string senderNumber = "+17245658130";
var twilioRestClient = new TwilioRestClient("AC47c7253af8c6fae4066c7fe3dbe4433c", "[AuthToken]");
var recipientNumber = Utils.GetNum(username);
twilioRestClient.SendMessage(senderNumber, recipientNumber, messageObj.ShortMessage, MessageCallback);
}
示例5: SendSms
/// <summary>
/// Send an SMS message
/// </summary>
/// <param name="from">The number to send the message from</param>
/// <param name="to">The number to send the message to</param>
/// <param name="body">The contents of the message, up to 160 characters</param>
/// <param name="statusCallbackUrl">The URL to notify of the message status</param>
/// <returns>An SMSMessage Instance resource</returns>
public static SMSMessage SendSms(string from, string to, string body, string statusCallbackUrl)
{
CheckForCredentials();
var twilio = new TwilioRestClient(AccountSid, AuthToken);
return twilio.SendSmsMessage(from, to, body, statusCallbackUrl);
}
示例6: SendAsync
public Task SendAsync(IdentityMessage message)
{
// Twilio Begin
var Twilio = new TwilioRestClient(
System.Configuration.ConfigurationManager.AppSettings["SMSAccountIdentification"],
System.Configuration.ConfigurationManager.AppSettings["SMSAccountPassword"]);
var result = Twilio.SendMessage(
System.Configuration.ConfigurationManager.AppSettings["SMSAccountFrom"],
message.Destination, message.Body
);
//Status is one of Queued, Sending, Sent, Failed or null if the number is not valid
Trace.TraceInformation(result.Status);
//Twilio doesn't currently have an async API, so return success.
return Task.FromResult(0);
// Twilio End
// ASPSMS Begin
// var soapSms = new MvcPWx.ASPSMSX2.ASPSMSX2SoapClient("ASPSMSX2Soap");
// soapSms.SendSimpleTextSMS(
// System.Configuration.ConfigurationManager.AppSettings["SMSAccountIdentification"],
// System.Configuration.ConfigurationManager.AppSettings["SMSAccountPassword"],
// message.Destination,
// System.Configuration.ConfigurationManager.AppSettings["SMSAccountFrom"],
// message.Body);
// soapSms.Close();
// return Task.FromResult(0);
// ASPSMS End
}
示例7: SendSMS
public string SendSMS(TxtMsgOutbound txtMsgOutbound)
{
if (!AppConfigSvcValues.Instance.SmsSimulationMode && OnWhiteList(txtMsgOutbound.MobilePhone))
{
ThrottleCount++;
if (ThrottleCount >= ThrottleMax)
{
_log.Warning("MaxThrottle count exceeded: " + ThrottleMax);
}
else
{
string msg = string.Format("Sending SMS to {0}. message: '{1}'. ThrottleCount:{2}", txtMsgOutbound.MobilePhone, txtMsgOutbound.Message, ThrottleCount);
_log.Info(msg);
var twilio = new TwilioRestClient(AppConfigSvcValues.Instance.TwilioAccountSid, AppConfigSvcValues.Instance.TwilioAuthToken);
Message ret = twilio.SendMessage(AppConfigSvcValues.Instance.SourcePhone, txtMsgOutbound.MobilePhone, txtMsgOutbound.Message); //FutureDev: Send async
_log.Info("Sent SMS, status: " + ret.Status);
if (ret.Status != "queued")
_log.Info("Error. Send to Twilio not successful. Status:" + ret.Status + " destPhone:" + txtMsgOutbound.MobilePhone);
}
}
else
{
string reason = AppConfigSvcValues.Instance.SmsSimulationMode ? "Simulation" : "not on whitelist";
txtMsgOutbound.NotSendReason = reason;
_log.Info("NOT Sending SMS to " + txtMsgOutbound.MobilePhone + " at " + txtMsgOutbound.MobilePhone + ". message: '" + txtMsgOutbound.Message + "' because " + reason);
}
_txtMsgOutboundDal.UpdateState(txtMsgOutbound, TxtMsgProcessState.Processed);
return txtMsgOutbound.Id;
}
示例8: SendTextMessage
public static void SendTextMessage(string message)
{
TwilioRestClient twilioClient = new TwilioRestClient
(ConfigurationManager.AppSettings["TwilioAcccountSid"], ConfigurationManager.AppSettings["TwilioAuthToken"]);
twilioClient.SendSmsMessage(ConfigurationManager.AppSettings["TwilioSenderPhone"],
ConfigurationManager.AppSettings["TwilioReceiverPhone"], message);
}
示例9: SendSmsToAllInvolved
public static void SendSmsToAllInvolved(int orderId, string action)
{
IstokDoorsDBContext db = new IstokDoorsDBContext();
var employeesToInform = db.Employees.Where(i => i.IsSmsInformed == true).ToList();
string messageText;
if (action == "ship")
{
messageText = " Заказ " + orderId + " oтправлен! Проверьте Журнал Учёта Складских Запасов для дополнительной информации.";
}
else
{
messageText = " Заказ " + orderId + " oтменён! Проверьте Журнал Учёта Складских Запасов для дополнительной информации.";
}
var twilio = new TwilioRestClient(TwilioSender.AccountSid, TwilioSender.AuthToken);
if (employeesToInform != null)
{
foreach (var employee in employeesToInform)
{
var message = twilio.SendMessage(TwilioSender.PhoneNumber, employee.PhoneNumber1, messageText, "");
}
}
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string fromNumber = Request["From"];
string toNumber = Request["To"];
string smsBody = Request["Body"];
//check for invalid requests
if (string.IsNullOrEmpty(smsBody))
return;
var twilio = new TwilioRestClient(TWILIO_ACCOUNT_ID, TWILIO_AUTH_TOKEY);
//Parse the message body, get the language
SmsMessage smsMsg = new SmsMessage(smsBody);
//Get the Google translation controller
GoogleTranslateController translateController = new GoogleTranslateController();
//Get the language of the sms.
string smsLanguageCode = translateController.DetectLanguage(smsMsg.Content);
//Get the target language code.
string targetLanguageCode = translateController.GetLanguageCode(smsMsg.Language, smsLanguageCode);
//Get the translated message
string translatedMessage = translateController.TranslateText(smsMsg.Content, targetLanguageCode);
translatedMessage = HttpUtility.HtmlDecode(translatedMessage);
var message = twilio.SendMessage(toNumber, fromNumber, translatedMessage, "");
}
示例11: Index
//
// GET: /SendMessages/
public ActionResult Index()
{
bool messages = true;
while (messages)
{
string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=AccountName;AccountKey=ACCOUNTKEY";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("messages");
CloudQueueMessage retrievedMessage = queue.GetMessage();
if (retrievedMessage == null)
{
messages = false;
}
string phone = retrievedMessage.AsString;
var twilio = new TwilioRestClient("accountSid", "authToken");
var call = twilio.InitiateOutboundCall("+YOURTWILIONUMBER", phone, "http://YOURSITE.azurewebsites.net/LookupCompliment/");
queue.DeleteMessage(retrievedMessage);
}
return View("Complete!");
}
示例12: TwilioProvider
public TwilioProvider(string accountSid, string authToken)
{
this.authToken = authToken;
this.accountSid = accountSid;
client = new TwilioRestClient(accountSid, authToken);
}
示例13: SendSMS
public bool SendSMS(string number, string message)
{
var settings = _accountSettings.GetVoiceSettings();
var client = new TwilioRestClient(settings.AccountSid, settings.AuthToken);
if (number.IndexOf('+') < 0)
{
number = "+" + number.Trim();
}
var smsNumber = WebConfigurationManager.AppSettings["TwilioNumber"];
var result = client.SendMessage(smsNumber, number, message);
if (result.RestException != null)
{
_logger.Error($"Exception thrown sending SMS to {number}. Ex - {result.RestException.Message}");
}
if (result.Status != "queued")
{
_logger.Error($"SMS sent status - {result.Status}, {result.ErrorMessage}");
}
_logger.Debug($"Sending SMS to {number} with content {message}");
return result.Status == "queued";
}
示例14: SendSMS
public TwilioSMSMessage SendSMS(string fromNumber, string toNumber, string text)
{
var twilio = new TwilioRestClient(SID, AuthToken);
try
{
var response = twilio.SendSmsMessage(fromNumber, toNumber, text);
if (response != null)
{
var message = new TwilioSMSMessage();
if (response.RestException != null)
{
message.ErrorCode = response.RestException.Code;
message.ErrorMessage = response.RestException.Message;
}
else
message.InjectFrom(response);
return message;
}
}
catch(Exception ex)
{
throw ex;
}
return null;
}
示例15: TwilioCommunicationService
public TwilioCommunicationService(string accountSid, string authToken, string msgUrl)
{
messagingBaseUrl = msgUrl;
_client = new TwilioRestClient(accountSid, authToken);
_callOptions = new CallOptions();
}