static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/user/account
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";
        const string serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string channelSid = "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string memberSid  = "MBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string body       = "body";

        // Send a message
        var     client  = new IpMessagingClient(accountSid, authToken);
        Message message = client.CreateMessage(serviceSid, channelSid, memberSid, body);

        Console.WriteLine(message);
    }
        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));
        }
示例#3
0
        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));
        }