コード例 #1
0
        private bool SendTextMessageViaTwillio(string number, string message, string departmentNumber)
        {
            TwilioClient.Init(Config.NumberProviderConfig.TwilioAccountSid, Config.NumberProviderConfig.TwilioAuthToken);
            MessageResource messageResource;

            try
            {
                if (String.IsNullOrWhiteSpace(departmentNumber) || NumberHelper.IsNexmoNumber(departmentNumber))
                {
                    //textMessage = twilio.SendMessage(Settings.Default.TwilioResgridNumber, number, message);

                    messageResource = MessageResource.Create(
                        from: new PhoneNumber(Config.NumberProviderConfig.TwilioResgridNumber),
                        to: new PhoneNumber(number),
                        body: message);

                    if (messageResource != null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    //textMessage = twilio.SendMessage(departmentNumber, number, message);

                    //messageResource = MessageResource.Create(
                    //	from: new PhoneNumber(departmentNumber),
                    //	to: new PhoneNumber(number),
                    //	body: message);
                    messageResource = MessageResource.Create(
                        from: new PhoneNumber(Config.NumberProviderConfig.TwilioResgridNumber),
                        to: new PhoneNumber(number),
                        body: message);

                    if (messageResource != null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #2
0
        public void CommunicateCall(string phoneNumber, UserProfile profile, Call call)
        {
            if (profile == null)
            {
                return;
            }

            TwilioClient.Init(Config.NumberProviderConfig.TwilioAccountSid, Config.NumberProviderConfig.TwilioAuthToken);

            if (!profile.VoiceForCall)
            {
                return;
            }

            string number = phoneNumber;

            if (String.IsNullOrWhiteSpace(number) || NumberHelper.IsNexmoNumber(number))
            {
                number = Config.NumberProviderConfig.TwilioResgridNumber;
            }

            if (number.Length == 11 && number[0] != Char.Parse("1"))
            {
                number = "+" + number;
            }

            if (profile.VoiceCallMobile)
            {
                if (!String.IsNullOrWhiteSpace(profile.GetPhoneNumber()))
                {
                    var options = new CreateCallOptions(new PhoneNumber(profile.GetPhoneNumber()), new PhoneNumber(number));
                    options.Url       = new Uri(string.Format(Config.NumberProviderConfig.TwilioVoiceCallApiTurl, profile.UserId, call.CallId));
                    options.Method    = "GET";
                    options.IfMachine = "Continue";

                    var phoneCall = CallResource.Create(options);
                }
            }

            if (profile.VoiceCallHome)
            {
                if (!String.IsNullOrWhiteSpace(profile.GetHomePhoneNumber()))
                {
                    var options = new CreateCallOptions(new PhoneNumber(profile.GetHomePhoneNumber()), new PhoneNumber(number));
                    options.Url       = new Uri(string.Format(Config.NumberProviderConfig.TwilioVoiceCallApiTurl, profile.UserId, call.CallId));
                    options.Method    = "GET";
                    options.IfMachine = "Continue";

                    var phoneCall = CallResource.Create(options);
                }
            }
        }