本文整理汇总了C#中Twilio.TwilioRestClient.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# TwilioRestClient.SendMessage方法的具体用法?C# TwilioRestClient.SendMessage怎么用?C# TwilioRestClient.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twilio.TwilioRestClient
的用法示例。
在下文中一共展示了TwilioRestClient.SendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
}
示例2: 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;
}
示例3: SendSms
public static void SendSms(string to, string message) {
var twilio = new TwilioRestClient(TwilioAccountSid, TwilioAuthToken);
twilio.SendMessage(FromNumber, to, message);
}
示例4: 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, "");
}
示例5: 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);
}
示例6: 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";
}
示例7: Get
public string Get([FromUri] string phoneNumber, string flatteristId, string flattery)
{
const string accountSid = "YOURSIDE";
const string authToken = "YOURTOKEN";
const string fromNumber = "YOURNUMBER";
var client = new TwilioRestClient(accountSid, authToken);
if (string.IsNullOrEmpty(flattery))
{
var call = client.InitiateOutboundCall(
fromNumber, // The number of the phone initiating the call
string.Format("+{0}", phoneNumber), // The number of the phone receiving call
string.Format("http://www.flatterist.com/{0}.mp3", flatteristId)
// The URL Twilio will request when the call is answered
);
if (call.RestException == null)
{
return string.Format("Started call: {0}", call.Sid);
}
return string.Format("Error: {0}", call.RestException.Message);
}
client.SendMessage(fromNumber, phoneNumber, flattery);
return string.Format("Sent message to {0}", phoneNumber);
}
示例8: 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);
}
示例9: Main
public void Main(string[] args)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
var client = new TwilioRestClient(Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"), Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"));
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("messages", false, false, false, null);
var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume("messages", true, consumer);
Console.WriteLine(" [*] Waiting for messages." +
"To exit press CTRL+C");
while (true)
{
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
var message = JsonConvert.DeserializeObject<Libs.Message>(Encoding.UTF8.GetString(ea.Body));
Console.WriteLine(" [x] Received {0}", message.Body);
// Send a nice message back to each one of the Inbound Messages
client.SendMessage("", message.From, "Thanks for seeing me @ dmconf15. Here's some Twilio <3 to get you started, just use the code NOSQL15. Hit me up @marcos_placona");
}
}
}
}
示例10: 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, "");
}
}
}
示例11: OnTimer
private void OnTimer(object sender, ElapsedEventArgs e)
{
try
{
EventLog.WriteEntry("Checking for new bark", EventLogEntryType.Information);
var newLatestBark = GetLatestBark().GetAwaiter().GetResult();
if (newLatestBark != null && (LatestBark == null || newLatestBark.Id != LatestBark.Id))
{
EventLog.WriteEntry("Sending new bark: " + newLatestBark.Bark, EventLogEntryType.Information);
if (!string.IsNullOrWhiteSpace(TwilioAccountSid) && !string.IsNullOrWhiteSpace(TwilioAuthToken))
{
var twilioClient = new TwilioRestClient(TwilioAccountSid, TwilioAuthToken);
twilioClient.SendMessage(TwilioSenderNumber, TwilioRecipentNumber, "🐶 " + newLatestBark.Bark);
}
else
{
EventLog.WriteEntry("Twilio account SID or AuthToken not configured", EventLogEntryType.Warning);
}
LatestBark = newLatestBark;
}
}
catch (Exception exception)
{
EventLog.WriteEntry(exception.Message, EventLogEntryType.Error);
}
}
示例12: SendMessage
public void SendMessage(string message, string imageUrl)
{
var twilioNumber = ConfigurationManager.AppSettings["TwilioPhoneNumber"];
var client = new TwilioRestClient(
ConfigurationManager.AppSettings["TwilioAccountSid"],
ConfigurationManager.AppSettings["TwilioAuthToken"]
);
if(imageUrl != "")
{
client.SendMessage(twilioNumber, this.PhoneNumber, message, new string[] { imageUrl });
}
else
{
client.SendMessage(twilioNumber, this.PhoneNumber, message);
}
}
示例13: SendText
//SendText method
public static void SendText(string number, string body)
{
string AccountSid = ConfigurationManager.AppSettings["acctSid"];
string AuthToken = ConfigurationManager.AppSettings["authToken"];
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage(ConfigurationManager.AppSettings["twilioNumber"], number, body);
}
示例14: SendHospital
public void SendHospital()
{
string AccountSid = "ACb2f1376756059a1e5519b0d067b82148"; //test code: "AC6c6ee3afd79c247db7007242708362bc";
string AuthToken = "0d08e8a2856d360e9cd0816e19baa15f";//test token :"d32142ce915c5377daa34e7efd06183b";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage("+14803606485 ", "+6596372198", "Dear Mr Tan, Mr Lee (no:98623241) is sending your son to hospital by taxi as he is too drunk with bad health.\n --By HangOver", "");
}
示例15: SendSms
public static void SendSms(string msg, string toNumber, string fromNumber)
{
var accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"];
var authToken = ConfigurationManager.AppSettings["TwilioAuthToken"];
var twilio = new TwilioRestClient(accountSid, authToken);
var sentMessage = twilio.SendMessage(fromNumber, toNumber, msg);
}