Esempio n. 1
0
        /// <summary>
        /// Creates an SMS communication with a CommunicationRecipient and adds it to the context.
        /// </summary>
        /// <param name="fromPerson">the Sender for the communication (For the communication.SenderPersonAlias). If null the name for the communication will be From: unknown person.</param>
        /// <param name="toPersonAliasId">To person alias identifier. If null the CommunicationRecipient is not created</param>
        /// <param name="message">The message.</param>
        /// <param name="fromPhone">From phone.</param>
        /// <param name="responseCode">The response code. If null/empty/whitespace then one is generated</param>
        /// <param name="communicationName">Name of the communication.</param>
        /// <returns></returns>
        public Communication CreateSMSCommunication(Person fromPerson, int?toPersonAliasId, string message, DefinedValueCache fromPhone, string responseCode, string communicationName)
        {
            var args = new CreateSMSCommunicationArgs
            {
                FromPerson            = fromPerson,
                ToPersonAliasId       = toPersonAliasId,
                CommunicationName     = communicationName,
                FromPhone             = fromPhone,
                Message               = message,
                ResponseCode          = responseCode,
                SystemCommunicationId = null
            };

            return(CreateSMSCommunication(args));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an SMS communication with a CommunicationRecipient and adds it to the context.
        /// </summary>
        /// <param name="createSMSCommunicationArgs">The create SMS communication arguments.</param>
        /// <returns></returns>
        public Communication CreateSMSCommunication(CreateSMSCommunicationArgs createSMSCommunicationArgs)
        {
            RockContext rockContext           = ( RockContext )this.Context;
            var         responseCode          = createSMSCommunicationArgs.ResponseCode;
            var         communicationName     = createSMSCommunicationArgs.CommunicationName;
            var         fromPerson            = createSMSCommunicationArgs.FromPerson;
            var         message               = createSMSCommunicationArgs.Message;
            var         fromPhone             = createSMSCommunicationArgs.FromPhone;
            var         systemCommunicationId = createSMSCommunicationArgs.SystemCommunicationId;
            var         toPersonAliasId       = createSMSCommunicationArgs.ToPersonAliasId;

            if (responseCode.IsNullOrWhiteSpace())
            {
                responseCode = Rock.Communication.Medium.Sms.GenerateResponseCode(rockContext);
            }

            // add communication for reply
            var communication = new Rock.Model.Communication
            {
                Name = communicationName,
                CommunicationType = CommunicationType.SMS,
                Status            = CommunicationStatus.Approved,
                ReviewedDateTime  = RockDateTime.Now,
                // NOTE: if this communication was created from a mobile device, fromPerson should never be null since a Nameless Person record should have been created if a regular person record wasn't found
                ReviewerPersonAliasId = fromPerson?.PrimaryAliasId,
                SenderPersonAliasId   = fromPerson?.PrimaryAliasId,
                IsBulkCommunication   = false,
                SMSMessage            = message,
                SMSFromDefinedValueId = fromPhone.Id,
                SystemCommunicationId = systemCommunicationId
            };

            if (toPersonAliasId != null)
            {
                var recipient = new Rock.Model.CommunicationRecipient();
                recipient.Status             = CommunicationRecipientStatus.Pending;
                recipient.PersonAliasId      = toPersonAliasId.Value;
                recipient.ResponseCode       = responseCode;
                recipient.MediumEntityTypeId = EntityTypeCache.Get("Rock.Communication.Medium.Sms").Id;
                recipient.SentMessage        = message;
                communication.Recipients.Add(recipient);
            }

            Add(communication);
            return(communication);
        }