Beispiel #1
0
        public string BuildEditUI([AllowNull] string uniqueControlId,
                                  IPlugInAPI.strTrigActInfo actionInfo)
        {
            SendMessageActionConfig config = SendMessageActionConfig.DeserializeActionConfig(actionInfo.DataIn);

            string toNumber = config.ToNumber;

            if (toNumber == null)
            {
                toNumber = "";
            }

            string message = config.Message;

            if (message == null)
            {
                message = "";
            }

            var toField = FormTextBox("ToNumber" + uniqueControlId, "To", toNumber);

            var messageField = FormTextBox("Message" + uniqueControlId, "Message", message);

            return(toField + "<br>" + messageField);
        }
Beispiel #2
0
        public bool HandleEvent(IPlugInAPI.strTrigActInfo actionInfo, TwilioServiceFacade twilioService)
        {
            SendMessageActionConfig config = SendMessageActionConfig.DeserializeActionConfig(actionInfo.DataIn);

            if (config.IsValid())
            {
                twilioService.SendMessageToTwilio(pluginConfig, config);
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        public IPlugInAPI.strMultiReturn ProcessPostUI([AllowNull] NameValueCollection postData,
                                                       IPlugInAPI.strTrigActInfo actionInfo)
        {
            var value = new IPlugInAPI.strMultiReturn
            {
                TrigActInfo = actionInfo
            };

            var config = new SendMessageActionConfig();

            if (postData != null && postData.HasKeys())
            {
                config.ToNumber = postData[0];
                config.Message  = postData[1];
                value.DataOut   = SendMessageActionConfig.SerializeActionConfig(config);
            }
            return(value);
        }
Beispiel #4
0
        public bool IsConfigured(IPlugInAPI.strTrigActInfo actionInfo)
        {
            SendMessageActionConfig config = SendMessageActionConfig.DeserializeActionConfig(actionInfo.DataIn);

            return(config.IsValid());
        }
Beispiel #5
0
        public string BuildViewUI(IPlugInAPI.strTrigActInfo actionInfo)
        {
            var config = SendMessageActionConfig.DeserializeActionConfig(actionInfo.DataIn);

            return($"Twilio sends a message to {config.ToNumber}");
        }
Beispiel #6
0
        public string PostBackProc(string data, [AllowNull] string user, int userRights)
        {
            NameValueCollection parts = HttpUtility.ParseQueryString(data);

            string form = parts["id"];

            if (form == "id_sendTestButton")
            {
                PluginConfig testConfig;
                using (testConfig = new PluginConfig(HS, true))
                {
                    PopulatePluginConfig(testConfig, parts);

                    string toNumber = parts["testNumber"];

                    TwilioServiceFacade twilioService = new TwilioServiceFacade(HS, testConfig.DebugLogging);

                    SendMessageActionConfig messageConfig = new SendMessageActionConfig();
                    messageConfig.ToNumber = toNumber;
                    messageConfig.Message  = @"$time: this is a test message from the HomeSeer Twilio Plugin.";

                    try
                    {
                        twilioService.SendMessageToTwilio(testConfig, messageConfig);
                        this.divToUpdate.Add(SuccessDivId, @"Test message was sent successfully!");
                        this.divToUpdate.Add(ErrorDivId, string.Empty);
                    }
                    catch (Exception e)
                    {
                        string errorMessage = e.Message;
                        if (errorMessage.Equals("Authenticate"))
                        {
                            errorMessage = "Invalid Auth Token";
                        }
                        this.divToUpdate.Add(SuccessDivId, string.Empty);
                        this.divToUpdate.Add(ErrorDivId, errorMessage);
                    }
                }
            }
            else if (form == NameToIdWithPrefix(SaveButtonName))
            {
                StringBuilder results = new StringBuilder();

                // Validate
                if (string.IsNullOrWhiteSpace(parts[AuthTokenId]))
                {
                    results.AppendLine("Auth Token is not Valid.<br>");
                }

                if (string.IsNullOrWhiteSpace(parts[AccountSIDId]))
                {
                    results.AppendLine("Account SID is not Valid.<br>");
                }

                if (string.IsNullOrWhiteSpace(parts[FromNumberId]))
                {
                    results.AppendLine("From Number is not Valid.<br>");
                }

                if (results.Length > 0)
                {
                    this.divToUpdate.Add(SuccessDivId, string.Empty);
                    this.divToUpdate.Add(ErrorDivId, results.ToString());
                }
                else
                {
                    this.divToUpdate.Add(SuccessDivId, "Settings have been saved successfully!");
                    this.divToUpdate.Add(ErrorDivId, string.Empty);

                    PopulatePluginConfig(this.pluginConfig, parts);

                    this.pluginConfig.FireConfigChanged();
                }
            }

            return(base.postBackProc(Name, data, user, userRights));
        }