Esempio n. 1
0
        /// <summary>
        ///     Handle one SMS message according to the registered handlers
        /// </summary>
        /// <param name="fromNumber"></param>
        /// <param name="message"></param>
        /// <param name="sentAtStr"></param>
        public static void Handle (string fromNumber, string message, DateTime sentAt)
        {
            // create a message object 
            PhoneMessage msg = new PhoneMessage (fromNumber, message, sentAt);

            //Ask all handlers if they want to handle the message object
            foreach (IPhoneMessageHandler handler in Handlers)
            {
                try
                {
                    // Want to handle this message ?
                    if (handler.Filter (msg))
                    {
                        // if Handle() returns true do not call the following handlers
                        if (handler.Handle (msg))
                            break;
                    }
                }
                catch
                {
                }
            }
            if (msg.ReplyMessage != "")
            {
                PhoneMessageTransmitter.Send (msg.FromNumber, msg.ReplyMessage);
            }
        }
Esempio n. 2
0
 public override bool Filter (PhoneMessage msg)
 {
     string[] smsParts = msg.Message.ToLower().Trim().Split (new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
     if (smsParts[0] == "start" && (smsParts[1] == "aktivist" || smsParts[1] == "activist"))
     {
         return true;
     }
     return false;
 }
Esempio n. 3
0
 public override bool Filter (PhoneMessage msg)
 {
     string[] smsParts = msg.Message.ToLower().Trim().Split (new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
     if (smsParts[0] == "pp" && smsParts[1] == "igen")
     {
         return true;
     }
     return false;
 }
Esempio n. 4
0
 public override bool Filter(PhoneMessage msg)
 {
     string[] smsParts = msg.Message.ToLower().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
     if ((smsParts[0] == "stopp" || smsParts[0] == "stop") && (smsParts[1] == "aktivist" || smsParts[1] == "activist"))
     {
         return(base.Filter(msg));
     }
     else
     {
         return(false);
     }
 }
Esempio n. 5
0
        public override bool Handle(PhoneMessage msg)
        {
            string from    = "*****@*****.**";
            string to      = "*****@*****.**";
            string subject = "SMS från '" + msg.FromNumber + "'";
            string body    = "Inkommet från telefonnummer: " + msg.FromNumber + "\r\n" +
                             "Meddelande: " + msg.Message + "\r\n" +
                             "Skickades: " + msg.SentAt.ToShortDateString() + " " + msg.SentAt.ToShortTimeString() +
                             "\r\n\r\n";

            if (msg.People.Count > 0)
            {
                foreach (BasicPerson bp in msg.People.Values)
                {
                    body += "Det telefonnumret tillhör medlem/aktivistnummer: ";
                    Person person = Person.FromBasic(bp);
                    body += person.Identity + " (";
                    if (!person.IsActivist)
                    {
                        body += "ej ";
                    }
                    body += "aktivist) \r\n";
                }
                string numbers = "";
                foreach (BasicPerson bp in msg.People.Values)
                {
                    numbers += "," + bp.PersonId;
                }
                body += "\r\n\r\n" + numbers.Substring(1);
            }
            else
            {
                body += "Hittade ingen medlem/aktivist i databasen med det numret.\r\n\r\n";
            }

            if (msg.ErrorMessage != "")
            {
                body += "\r\nComment from SMS processing: " + msg.ErrorMessage;
            }

            ForwardMessage(from, to, subject, body);
            msg.ReplyMessage +=
                "\r\nDitt meddelande har vidarebefordrats till [email protected]. Kontakta oss om du undrar över något.";
            PWLog.Write(PWLogItem.None, 0, PWLogAction.SMSHandled, "Forwarded SMS from " + msg.FromNumber + " to " + to,
                        msg.Message + "\r\n" + msg.ErrorMessage);

            return(true);
        }
Esempio n. 6
0
        public override bool Handle (PhoneMessage msg)
        {
            Trace.WriteLine (msg); // use parameter to suppress warning

            /* -- all of the phone message handling need to move to app or plugin

            // register new activist
            // check for words: activist <postal code> <e-mail>
            msg.ErrorMessage = "\r\nRequest to register as activist.";
            if (msg.People.Count > 0)
            {
                foreach (BasicPerson bPerson in msg.People.Values)
                {
                    Person person = Person.FromBasic(bPerson);
                    if (person.IsActivist)
                    {
                        if (msg.People.Count == 1)
                        {
                            // Only one and is already activist.
                            msg.ErrorMessage = "\r\nRequest to register as activist.";
                            msg.ErrorMessage += "\r\nThis person IS already an activist.";
                        }
                    }
                    else if (msg.People.Count == 1)
                    {
                        int partyOrgId = person.NationalPartyOrg(false);
                        ActivistEvents.CreateActivistWithLogging(person.Geography, person, "Registered by SMS", EventSource.SMS, true, true, partyOrgId);
                        msg.ReplyMessage = "Välkommen som aktivist i Piratpartiet!";

                        return true; // Handled;
                    }
                }
                if (msg.People.Count > 1)
                {
                    msg.ReplyMessage = "Misslyckades utföra åtgärden.";
                    msg.ErrorMessage = "\r\nRequest to renew membership.";
                    msg.ErrorMessage = "\r\nMultiple hits.\r\n\r\nHave replied:" + msg.ReplyMessage;
                }
            }
            else
            {
                // Handle further info in the message 
                // check for words: activist <postal code> <e-mail>

            }-- */
            return false;
        }
Esempio n. 7
0
 public override bool Handle(PhoneMessage msg)
 {
     //TODO: Decide if more than one hit is OK
     if (msg.People.Count > 0)
     {
         foreach (BasicPerson bPerson in msg.People.Values)
         {
             Person person = Person.FromBasic(bPerson);
             if (person.IsActivist)
             {
                 ActivistEvents.TerminateActivistWithLogging(person, EventSource.SMS);
                 return(true);
             }
         }
     }
     msg.ReplyMessage = "Misslyckades utföra åtgärden: Vi kunde inte hitta ditt telefonnummer i vårt register.";
     msg.ErrorMessage = "\r\nRequest to stop being an aktivist.";
     msg.ErrorMessage = "\r\nDid not find the phone number in the database.\r\n\r\nHave replied:" + msg.ReplyMessage;
     return(false);
 }
Esempio n. 8
0
 public virtual bool Filter (PhoneMessage message)
 {
     return (message.People.Count > 0);
 }
Esempio n. 9
0
        public override bool Handle (PhoneMessage msg)
        {
            /* This needs to move to a plugin. */

            /*
            // renew memberships
            // if there is a third parameter it is the person#
            string[] smsParts = msg.Message.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            int personId = 0;

            if (smsParts.Length > 2)
            {
                // personid is specified
                try
                {
                    personId = Int32.Parse(smsParts[2]);
                    PWEvents.CreateEvent(EventSource.CustomServiceInterface, EventType.ReceivedMembershipPayment,
                                                                personId, Organization.PPSEid, 0, personId, 0,
                                                                msg.Message.Replace(" ", "_") + "/" + msg.FromNumber);
                    msg.ReplyMessage = "Det kommer strax ett e-mail som bekräftar förnyelsen.";

                    return true; // Handled;
                }
                catch (Exception)
                {
                    msg.ReplyMessage += "Kunde inte tolka tredje parametern (medlemsnummer).";
                    msg.ErrorMessage += "Person# parameter not valid.\r\nHave replied: " + msg.ReplyMessage;
                }
            }
            else
            {
                // personid is NOT specified, base on phone number
                if (msg.People.Count > 0)
                {
                    int countOfMembers = 0;
                    Person person = null;
                    foreach (BasicPerson bPerson in msg.People.Values)
                    {
                        person = Person.FromBasic(bPerson);
                        if (person.GetRecentParticipations(Membership.GracePeriod).Count > 0)
                        {
                            countOfMembers++;
                        }
                    }
                    if (countOfMembers == 1)
                    {
                        PWEvents.CreateEvent(EventSource.CustomServiceInterface, EventType.ReceivedMembershipPayment,
                                                                    person.PersonId, Organization.PPSEid, 0, personId, 0,
                                                                    msg.Message.Replace(" ", "_") + "/" + msg.FromNumber);
                        msg.ReplyMessage = "Det kommer strax ett e-mail som bekräftar förnyelsen.";

                        return true; // Handled;
                    }
                    else
                    {
                        msg.ReplyMessage = "Misslyckades utföra åtgärden.";
                        msg.ErrorMessage = "\r\nRequest to renew membership.";
                        msg.ErrorMessage = "\r\nMultiple hits.\r\n\r\nHave replied:" + msg.ReplyMessage;
                    }
                }
                else
                {
                    msg.ReplyMessage = "Misslyckades utföra åtgärden: Vi kunde inte hitta ditt telefonnummer i vårt register.";
                    msg.ErrorMessage = "\r\nRequest to renew membership.";
                    msg.ErrorMessage = "\r\nDid not find the phone number in the database.\r\n\r\nHave replied:" + msg.ReplyMessage;
                }
            }


            return false; */


            // use parameters to suppress warnings
            Trace.WriteLine (msg);
            return false;
        }
Esempio n. 10
0
        public override bool Handle (PhoneMessage msg)
        {

            string from = "*****@*****.**";
            string to = "*****@*****.**";
            string subject = "SMS från '" + msg.FromNumber + "'";
            string body = "Inkommet från telefonnummer: " + msg.FromNumber + "\r\n" +
                          "Meddelande: " + msg.Message + "\r\n" +
                          "Skickades: " + msg.SentAt.ToShortDateString() + " " + msg.SentAt.ToShortTimeString() + "\r\n\r\n";

            if (msg.People.Count > 0)
            {
                foreach (BasicPerson bp in msg.People.Values)
                {
                    body += "Det telefonnumret tillhör medlem/aktivistnummer: ";
                    Person person = Person.FromBasic(bp);
                    body += person.Identity + " (";
                    if (!person.IsActivist)
                        body += "ej ";
                    body += "aktivist) \r\n";

                }
                string numbers = "";
                foreach (BasicPerson bp in msg.People.Values)
                {
                    numbers += "," + bp.PersonId;
                }
                body += "\r\n\r\n" + numbers.Substring(1);
            }
            else
                body += "Hittade ingen medlem/aktivist i databasen med det numret.\r\n\r\n";

            if (msg.ErrorMessage != "")
            {
                body += "\r\nComment from SMS processing: " + msg.ErrorMessage;
            }

            ForwardMessage(from, to, subject, body);
            msg.ReplyMessage += "\r\nDitt meddelande har vidarebefordrats till [email protected]. Kontakta oss om du undrar över något.";
            PWLog.Write(PWLogItem.None, 0, PWLogAction.SMSHandled, "Forwarded SMS from " + msg.FromNumber + " to " + to, msg.Message + "\r\n" + msg.ErrorMessage);

            return true;
        }
Esempio n. 11
0
 public override bool Filter (PhoneMessage msg)
 {
     string[] smsParts = msg.Message.ToLower().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
     if ((smsParts[0] == "stopp" || smsParts[0] == "stop") && (smsParts[1] == "aktivist" || smsParts[1] == "activist"))
     {
         return base.Filter(msg);
     }
     else
         return false;
 }
Esempio n. 12
0
 public override bool Filter (PhoneMessage message)
 {
     return true; //Catch all
 }
Esempio n. 13
0
 public override  bool Filter (PhoneMessage message)
 {
     return true; //Catch all
 }
Esempio n. 14
0
 public override bool Handle (PhoneMessage msg)
 {
     //TODO: Decide if more than one hit is OK
     if (msg.People.Count > 0)
     {
         foreach (BasicPerson bPerson in msg.People.Values)
         {
             Person person = Person.FromBasic(bPerson);
             if (person.IsActivist)
             {
                 ActivistEvents.TerminateActivistWithLogging(person, EventSource.SMS);
                 return true;
             }
         }
     }
     msg.ReplyMessage = "Misslyckades utföra åtgärden: Vi kunde inte hitta ditt telefonnummer i vårt register.";
     msg.ErrorMessage = "\r\nRequest to stop being an aktivist.";
     msg.ErrorMessage = "\r\nDid not find the phone number in the database.\r\n\r\nHave replied:" + msg.ReplyMessage;
     return false;
 }
Esempio n. 15
0
 public virtual bool Filter (PhoneMessage message)
 {
     return (message.People.Count > 0);
 }
Esempio n. 16
0
        /// <summary>
        /// Handle one SMS message according to the registered handlers
        /// </summary>
        /// <param name="fromNumber"></param>
        /// <param name="message"></param>
        /// <param name="sentAtStr"></param>
        public static void Handle (string fromNumber, string message, DateTime sentAt)
        {

            // create a message object 
            PhoneMessage msg = new PhoneMessage(fromNumber, message, sentAt);

            //Ask all handlers if they want to handle the message object
            foreach (IPhoneMessageHandler handler in Handlers)
            {
                try
                {
                    // Want to handle this message ?
                    if (handler.Filter(msg))
                    {

                        // if Handle() returns true do not call the following handlers
                        if (handler.Handle(msg))
                            break;
                    }
                }
                catch
                {
                }
            }
            if (msg.ReplyMessage != "")
            {
                PhoneMessageTransmitter.Send(msg.FromNumber, msg.ReplyMessage);
            }
        }
Esempio n. 17
0
        public override bool Handle (PhoneMessage msg)
        {
            // renew memberships
            // if there is a third parameter it is the person#
            string[] smsParts = msg.Message.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            int personId = 0;

            if (smsParts.Length > 2)
            {
                // personid is specified
                try
                {
                    personId = Int32.Parse(smsParts[2]);
                    PWEvents.CreateEvent(EventSource.CustomServiceInterface, EventType.ReceivedMembershipPayment,
                                                                personId, Organization.PPSEid, 0, personId, 0,
                                                                msg.Message.Replace(" ", "_") + "/" + msg.FromNumber);
                    msg.ReplyMessage = "Det kommer strax ett e-mail som bekräftar förnyelsen.";

                    return true; // Handled;
                }
                catch (Exception)
                {
                    msg.ReplyMessage += "Kunde inte tolka tredje parametern (medlemsnummer).";
                    msg.ErrorMessage += "Person# parameter not valid.\r\nHave replied: " + msg.ReplyMessage;
                }
            }
            else
            {
                // personid is NOT specified, base on phone number
                if (msg.People.Count > 0)
                {
                    int countOfMembers = 0;
                    Person person = null;
                    foreach (BasicPerson bPerson in msg.People.Values)
                    {
                        person = Person.FromBasic(bPerson);
                        if (person.GetRecentMemberships(Membership.GracePeriod).Count > 0)
                        {
                            countOfMembers++;
                        }
                    }
                    if (countOfMembers == 1)
                    {
                        PWEvents.CreateEvent(EventSource.CustomServiceInterface, EventType.ReceivedMembershipPayment,
                                                                    person.PersonId, Organization.PPSEid, 0, personId, 0,
                                                                    msg.Message.Replace(" ", "_") + "/" + msg.FromNumber);
                        msg.ReplyMessage = "Det kommer strax ett e-mail som bekräftar förnyelsen.";

                        return true; // Handled;
                    }
                    else
                    {
                        msg.ReplyMessage = "Misslyckades utföra åtgärden.";
                        msg.ErrorMessage = "\r\nRequest to renew membership.";
                        msg.ErrorMessage = "\r\nMultiple hits.\r\n\r\nHave replied:" + msg.ReplyMessage;
                    }
                }
                else
                {
                    msg.ReplyMessage = "Misslyckades utföra åtgärden: Vi kunde inte hitta ditt telefonnummer i vårt register.";
                    msg.ErrorMessage = "\r\nRequest to renew membership.";
                    msg.ErrorMessage = "\r\nDid not find the phone number in the database.\r\n\r\nHave replied:" + msg.ReplyMessage;
                }
            }


            return false;

        }
Esempio n. 18
0
 public override bool Filter (PhoneMessage msg)
 {
     string[] smsParts = msg.Message.ToLower().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
     if (smsParts[0] == "pp" && smsParts[1] == "igen")
     {
         return true;
     }
     else
         return false;
 }
Esempio n. 19
0
        public override bool Handle (PhoneMessage msg)
        {
            // register new activist
            // check for words: activist <postal code> <e-mail>
            msg.ErrorMessage = "\r\nRequest to register as activist.";
            if (msg.People.Count > 0)
            {
                foreach (BasicPerson bPerson in msg.People.Values)
                {
                    Person person = Person.FromBasic(bPerson);
                    if (person.IsActivist)
                    {
                        if (msg.People.Count == 1)
                        {
                            // Only one and is already activist.
                            msg.ErrorMessage = "\r\nRequest to register as activist.";
                            msg.ErrorMessage += "\r\nThis person IS already an activist.";
                        }
                    }
                    else if (msg.People.Count == 1)
                    {
                        int partyOrgId = person.NationalPartyOrg(false);
                        ActivistEvents.CreateActivistWithLogging(person.Geography, person, "Registered by SMS", EventSource.SMS, true, true, partyOrgId);
                        msg.ReplyMessage = "Välkommen som aktivist i Piratpartiet!";

                        return true; // Handled;
                    }
                }
                if (msg.People.Count > 1)
                {
                    msg.ReplyMessage = "Misslyckades utföra åtgärden.";
                    msg.ErrorMessage = "\r\nRequest to renew membership.";
                    msg.ErrorMessage = "\r\nMultiple hits.\r\n\r\nHave replied:" + msg.ReplyMessage;
                }
            }
            else
            {
                // Handle further info in the message 
                // check for words: activist <postal code> <e-mail>

            }
            return false;

        }
Esempio n. 20
0
 public virtual bool Handle (PhoneMessage message)
 {
     return false;
 }
Esempio n. 21
0
 public virtual bool Handle (PhoneMessage message)
 {
     return false;
 }