static void Main(string[] args) { // Find your Account Sid and Auth Token at twilio.com/user/account const string accountSid = "accountSid"; const string authToken = "authToken"; const string serviceSid = "serviceSid"; const string channelSid = "channelSid"; const string messageSid = "messageSid"; // Retrieve Message var client = new IpMessagingClient(accountSid, authToken); Message message = client.GetMessage(serviceSid, channelSid, messageSid); Console.WriteLine(message); }
static void Main(string[] args) { // Find your Account Sid and Auth Token at twilio.com/user/account const string accountSid = "accountSid"; const string authToken = "authToken"; const string serviceSid = "serviceSid"; const string channelSid = "channelSid"; // List all Messages var client = new IpMessagingClient(accountSid, authToken); MessageResult result = client.ListMessages(serviceSid, channelSid); Console.WriteLine(result); }
static void Main(string[] args) { // Find your Account Sid and Auth Token at twilio.com/user/account const string accountSid = "accountSid"; const string authToken = "authToken"; const string serviceSid = "serviceSid"; const string channelSid = "channelSid"; const string messageSid = "messageSid"; // Update Message var client = new IpMessagingClient(accountSid, authToken); var newBody = "New text for the message."; var message = client.UpdateMessage(serviceSid, channelSid, messageSid, newBody); Console.WriteLine(message); }
public ActionResult ConfigureService() { var client = new IpMessagingClient( ConfigurationManager.AppSettings["TwilioApiKey"], ConfigurationManager.AppSettings["TwilioApiSecret"]); client.UpdateService(ConfigurationManager.AppSettings["TwilioIpmServiceSid"], null, null, null, null, 5, new Dictionary<string, string> { { "Webhooks.OnMessageSend.Url", "http://[YOUR_NGROK_URL]/Home/MessageAdded" }, { "Webhooks.OnMessageSend.Method", "POST" }, { "Webhooks.OnMessageSend.Format", "XML" } }); return new HttpStatusCodeResult(HttpStatusCode.NoContent); }
public IActionResult SMSAdded(string To, string From, string Body) { var client = new IpMessagingClient(Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"), Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN")); using (var _db = new FriendsContext()){ var channelSid = _db.Friends.FirstOrDefault(s => s.PhoneNumber == From).ChannelSid; var message = client.CreateMessage( Environment.GetEnvironmentVariable("TWILIO_IPM_SERVICE_SID"), channelSid, From.RemoveSpecialCharacters(), Body ); if (message.RestException!=null) { string result = message.RestException.Message; return Content(result); } } return Content(string.Empty); }
public async Task<ActionResult> MessageAdded(string To, string Body, string From) { System.Diagnostics.Debug.WriteLine(Body); Body = await Translate(Body, "en", "es"); System.Diagnostics.Debug.WriteLine(Body); var client = new IpMessagingClient( ConfigurationManager.AppSettings["TwilioApiKey"], ConfigurationManager.AppSettings["TwilioApiSecret"]); var result = client.CreateMessage( ConfigurationManager.AppSettings["TwilioIpmServiceSid"], To, From, Body); if (result.RestException != null) { System.Diagnostics.Debug.WriteLine(result.RestException.Message); } return new HttpStatusCodeResult(403); }
public FriendController() { _db = new FriendsContext(); _client = new IpMessagingClient(Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"), Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN")); }