Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public bool HandleEvent(IPlugInAPI.strTrigActInfo actionInfo, TwilioServiceFacade twilioService)
 {
     return(false);
 }
Ejemplo n.º 3
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));
        }