public static void Main(string[] args) { CloudRail.AppKey = "[Your CloudRail Key]"; List <ISMS> services = new List <ISMS>(); Nexmo nexmo = new Nexmo(null, "[Nexmo API Key]", "[Nexmo API Secret]"); services.Add(nexmo); Twilio twilio = new Twilio(null, "[Twilio Account SID]", "[Twilio Auth Token]"); services.Add(twilio); Twizo twizo = new Twizo(null, "[Twizo Key]"); services.Add(twizo); foreach (ISMS service in services) { try { service.SendSMS("[Sending Number]", "[Receiving Number]", "Hello from " + service); } catch (Exception e) { Console.WriteLine(e); } } }
public async Task GetTextMessageBodyAsync_Sentence_NullOrEmpty_Ignored(string nullOrEmpty) { var firstSentenceProvider = new Mock <IResponseSentenceProvider>(); firstSentenceProvider.Setup(p => p.GetResponseSentence( It.IsAny <GameOption>(), It.IsAny <GameOption>(), It.IsAny <TurnWinner>(), It.IsAny <PlayerTurnResult>())) .Returns("A"); var secondSentenceProvider = new Mock <IResponseSentenceProvider>(); secondSentenceProvider.Setup(p => p.GetResponseSentence( It.IsAny <GameOption>(), It.IsAny <GameOption>(), It.IsAny <TurnWinner>(), It.IsAny <PlayerTurnResult>())) .Returns(nullOrEmpty); var target = new Twilio(MockStatelessServiceContextFactory.Default, new[] { firstSentenceProvider.Object, secondSentenceProvider.Object }); var result = await target.GetTextMessageBodyAsync( GameOption.Paper, GameOption.Scissor, TurnWinner.Tie, null); Assert.AreEqual("A", result); }
public async Task GetTextMessageBodyAsync_Exception_BubblesUp() { var firstSentenceProvider = new Mock <IResponseSentenceProvider>(); firstSentenceProvider.Setup(p => p.GetResponseSentence( It.IsAny <GameOption>(), It.IsAny <GameOption>(), It.IsAny <TurnWinner>(), It.IsAny <PlayerTurnResult>())) .Returns("A"); var secondSentenceProvider = new Mock <IResponseSentenceProvider>(); secondSentenceProvider.Setup(p => p.GetResponseSentence( It.IsAny <GameOption>(), It.IsAny <GameOption>(), It.IsAny <TurnWinner>(), It.IsAny <PlayerTurnResult>())) .Throws(new ValidationException("Some exception.")); var target = new Twilio(MockStatelessServiceContextFactory.Default, new[] { firstSentenceProvider.Object, secondSentenceProvider.Object }); var exception = await Assert.ThrowsExceptionAsync <ValidationException>( async() => await target.GetTextMessageBodyAsync( GameOption.Paper, GameOption.Scissor, TurnWinner.Tie, null)); Assert.AreEqual("Some exception.", exception.Message); }
public async Task<IActionResult> RedirectTextReply(Twilio.Message message) { string sendTo = message.From; try { Logger.LogInformation("MessageController_RedirectTextReply", $"Starting to process DivineBot::from:{message?.From}::message:{message?.Body}", username: CurrentUser, clientIp: DisplayUrl, serverIp: Environment.MachineName).Forget(); string msgTwiML = ""; string body = ""; //todo: make 10 a constant if (sendTo.Length > 10) { sendTo = sendTo.Substring(sendTo.Length - 10); } var isAuthorized = await (PhoneIsAuthorized(sendTo)); if (isAuthorized) { var result = await Conversation.SendAsync(new Message { ConversationId = message.From, From = new ChannelAccount(message.From), Created = message.DateCreated, Text = message.Body }, ()=> Chain.From(() => new DivineBotDialog() )); var botResult = JsonConvert.DeserializeObject<DivineBotRequest>(result.Text); body = await botResult.ProcessBotAsync(repositories); } else { body = "Sorry, not authorized"; NotifyAdmin($"{sendTo} was NOT authorized. Message: {message.Body}"); } msgTwiML = $@"<Response><Message to=""{sendTo}"">{body}</Message></Response>"; Logger.LogInformation("MessageController_RedirectTextReply", msgTwiML, username: CurrentUser, clientIp: DisplayUrl, serverIp: Environment.MachineName).Forget(); return Content(msgTwiML, "text/xml"); } catch (Exception ex) { await Logger.LogError("MessageController_RedirectTextReply", ex.Message, CurrentUser, Environment.MachineName, exception: ex); return Content($@"<Response><Message to=""{sendTo}"">An error occurred while processing</Message></Response>", "text/xml"); } }
public async Task GetUserInputAsync_Scissor(string input) { var target = new Twilio(MockStatelessServiceContextFactory.Default, null); var result = await target.GetUserInputAsync(input); Assert.AreEqual(GameOption.Scissor, result); }
public TwilioResponse EntryPoint(Twilio.Mvc.VoiceRequest request) { TwilioResponse response = new TwilioResponse(); response.Say("Welcome to the IVR"); return response; }
public static async Task <TwilioMessage> GetMessageInfo() { var smsInfo = new RestCredentialInfo(); smsInfo.ReadFromConfiguration(); var twilioMessage = await Twilio.GetMessage(smsInfo, "SM1e8208f4b4e44720bafc9ea0334eb72d"); return(twilioMessage); }
public async Task GetUserInputAsync_InvalidInput() { var target = new Twilio(MockStatelessServiceContextFactory.Default, null); var exception = await Assert.ThrowsExceptionAsync <ValidationException>( async() => await target.GetUserInputAsync("Garbage")); Assert.AreEqual("Input Garbage not recognized.", exception.Message); }
public static async Task SendMessage() { var twilioMessage = new TwilioMessage(); twilioMessage.ReadFromConfiguration(); twilioMessage.Message = "All in the game"; var smsInfo = new RestCredentialInfo(); smsInfo.ReadFromConfiguration(); message = await Twilio.SendMessage(smsInfo, twilioMessage); }
static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; Twilio.Init(accountSid, authToken); var call = CallResource.Create(new PhoneNumber("+14155551212"), new PhoneNumber("+15017250604"), url: new Uri("http://demo.twilio.com/docs/voice.xml"), record: true); Console.WriteLine(call.Sid); }
public async void OnInitialized() { try { var client = new HttpClient(); var token = await client.GetStringAsync(httpServer + "/Client/Token?clientName=" + clientName); _device = Twilio.CreateDevice(token, null); var intent = new Intent(this.ApplicationContext, typeof(MainActivity)); var pendingIntent = PendingIntent.GetActivity(this.ApplicationContext, 0, intent, PendingIntentFlags.UpdateCurrent); _device.SetIncomingIntent(pendingIntent); } catch (Exception ex) { Log.Info(TAG, "Error: " + ex.Message); } }
public async void OnInitialized() { Console.WriteLine("Twilio SDK is ready."); try { var client = new HttpClient(); var token = await client.GetStringAsync($"*** YOUR AUTH TOKEN URL ***"); Device = Twilio.CreateDevice(token, null); var intent = new Intent(context, typeof(MainActivity)); var pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.UpdateCurrent); Device.SetIncomingIntent(pendingIntent); Device.SetDeviceListener(this); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
private const string clientName = "xamarin"; //alice protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); Twilio.Initialize(this.ApplicationContext, this); // Get our button from the layout resource, // and attach an event to it Button call = FindViewById <Button> (Resource.Id.callButton); EditText phoneEditText = FindViewById <EditText> (Resource.Id.phoneNumberEditText); call.Click += delegate { var parameters = new Dictionary <string, string> () { { "from", myPhoneNum }, { "to", phoneEditText.Text } }; _connection = _device.Connect(parameters, null); }; Button anyKey = FindViewById <Button> (Resource.Id.anyKeyButton); anyKey.Click += delegate { if (_connection != null && _connection.State == ConnectionState.Connected) { _connection.SendDigits("1"); } }; Button hangup = FindViewById <Button> (Resource.Id.hangupButton); hangup.Click += delegate { _connection.Disconnect(); }; }
public MonkeyPhone(Context context) { this.context = context; Twilio.Initialize(context, this); }
public void NextInstruction(Twilio.Mvc.VoiceRequest request) { throw new NotImplementedException(); }