Example #1
0
        public virtual IEnumerable sendCallNotification(PXAdapter adapter)
        {
            ARInvoice invoice = PXCache <ARInvoice> .CreateCopy(Base.Document.Current);

            PXLongOperation.StartOperation(Base, delegate
            {
                ARInvoiceEntry invGraph         = PXGraph.CreateInstance <ARInvoiceEntry>();
                invGraph.Document.Current       = invoice;
                ARInvoiceEntryPXExt invGraphExt = invGraph.GetExtension <ARInvoiceEntryPXExt>();
                invGraphExt.SendTwilioNotification(invGraph, TwilioNotificationType.OutBoundCall);
            });
            return(adapter.Get());
        }
        protected virtual void ARTwilioNotificationProcessFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            ARTwilioNotificationProcessFilter filter = (ARTwilioNotificationProcessFilter)e.Row;

            if (filter != null && !String.IsNullOrEmpty(filter.Action) && (filter.Action != "<SELECT>"))
            {
                ARDocumentList.SetProcessDelegate <ARInvoiceEntry>(
                    delegate(ARInvoiceEntry graph, ARInvoice invoice)
                {
                    graph.Clear();
                    graph.Document.Current          = invoice;
                    ARInvoiceEntryPXExt invGraphExt = graph.GetExtension <ARInvoiceEntryPXExt>();
                    invGraphExt.SendTwilioNotification(graph, filter.Action);
                });
            }
        }
Example #3
0
        public void SendTwilioNotification(ARInvoiceEntry invGraph, string notificationType, bool isMassProcess = false)
        {
            ARInvoiceEntryPXExt invGraphExt = invGraph.GetExtension <ARInvoiceEntryPXExt>();

            //Raise error if Twilio Integration Setup not configured
            if (invGraphExt.TwilioSetupInfo.Current == null)
            {
                throw new PXException(Messages.TwilioAccountNotSetup);
            }

            //Get current billing contact
            if (invGraph.Billing_Contact.Current == null)
            {
                invGraph.Billing_Contact.Current = invGraph.Billing_Contact.Select();
            }
            ARContact contact = invGraph.Billing_Contact.Current;

            if (contact == null || String.IsNullOrEmpty(contact.Phone1))
            {
                throw new PXException(Messages.InvoiceBillingContactNotExists);
            }

            int?iNotificationID = (notificationType == TwilioNotificationType.SMS) ?
                                  invGraphExt.TwilioSetupInfo.Current?.SMSNotificationID :
                                  invGraphExt.TwilioSetupInfo.Current?.CallNotificationID;

            //Raise notification appropriate error message
            if (notificationType == TwilioNotificationType.SMS)
            {
                if (iNotificationID == null)
                {
                    throw new PXException(Messages.SMSNotificationIDNotSpecified);
                }
            }
            else if (notificationType == TwilioNotificationType.OutBoundCall)
            {
                if (iNotificationID == null)
                {
                    throw new PXException(Messages.CallNotificationIDNotSpecified);
                }
            }
            else
            {
                throw new PXException(Messages.UNSpecifiedTwilioNotificationType);
            }

            //Get the notification
            PX.SM.Notification notification = PXSelect <PX.SM.Notification,
                                                        Where <PX.SM.Notification.notificationID, Equal <Required <PX.SM.Notification.notificationID> > > > .
                                              Select(invGraph, invGraphExt.TwilioSetupInfo.Current.SMSNotificationID);

            if (notification == null)
            {
                throw new PXException(Messages.NotificationNotFound);
            }

            //Process the datafields and get Subject and Notification Body ready.
            string subjectNotification = String.Format("{0} - {1}", (notificationType == TwilioNotificationType.SMS) ?
                                                       Messages.SMSSubjectPrefix : Messages.CallSubjectPrefix,
                                                       PX.Data.Wiki.Parser.PXTemplateContentParser.
                                                       Instance.Process(notification.Subject, invGraph,
                                                                        invGraph.Document.Current.GetType(), null));
            string bodyNotification = PX.Data.Wiki.Parser.PXTemplateContentParser.
                                      Instance.Process(notification.Body, invGraph,
                                                       invGraph.Document.Current.GetType(), null);

            //Create Twilio Notification
            var twilio = new TwilioNotification(invGraphExt.TwilioSetupInfo.Current.TwilioAccountSid,
                                                invGraphExt.TwilioSetupInfo.Current.TwilioAuthToken)
            {
                Origin = invGraphExt.TwilioSetupInfo.Current.TwilioFromPhoneNumber
            };

            if (notificationType == TwilioNotificationType.SMS)
            {
                twilio.SendSMS(contact.Phone1, PX.Data.Search.SearchService.Html2PlainText(bodyNotification));
            }
            else if (notificationType == TwilioNotificationType.OutBoundCall)
            {
                twilio.SendCall(contact.Phone1, PX.Data.Search.SearchService.Html2PlainText(bodyNotification));
            }
            else
            {
                throw new PXException(Messages.UNSpecifiedTwilioNotificationType);
            }

            //Create Activity in Acumataica
            CreateTwilioNotificationActivity(invGraph, subjectNotification, bodyNotification);
        }