9 Replies Latest reply on Feb 10, 2015 9:14 PM by ChewCheeLim

    Create Contact using custom delivery channel

    ChewCheeLim

      Hi there: I am trying to create a list of contacts to use my custom delivery channel in C#. How should I go about doing it?   See below 1st pic.

      I want to mimic the 'New Contact' action in PSE. During this contact creation, I don't have to define my notification. However, when I tried the AF SDK, it seems that I need to have a notification defined (see picture 2). Same as in the sample code I found comes with the install. (CreateNotificationRule project.)

      Could someone point me to the right direction?

       

       

        • Re: Create Contact using custom delivery channel
          Mike Zboray

          So in this view there are two underlying AF SDK objects: AFContact and AFNotificationContactTemplate. The AFContact is the "Chew Chee Lim" node in the tree. The AFNotificationContactTemplate is the "Chew Chee Lim - Email" node in tree. Neither one of those needs an AFNotification. The sample code just happens to create the notification first, but that is not required.

           

          string name = "Chew Chee Lim";
          string customDC = "MyDeliveryChannel";
          var contact = AFContact.FindContact(system, name);
          var nct = new AFNotificationContactTemplate(contact, string.Format("{0} - {1}", name, customDC));
          nct.DeliveryChannelPlugIn = system.DeliveryChannelPlugIns[customDC];
          nct.DeliveryChannelPlugIn.ConfigString = ""; // whatever your custom configuration is
          nct.CheckIn();
          

           

          To send a notification to this endpoint you would then:

           

          Guid id = Guid.Parse("") // whatever the guid of the notification is, or you can use one of the other FindNotification calls.
          var notifiation = AFNotification.FindNotification(system, id);
          notification.NotificationContacts.Add(nct);
          notification.CheckIn();
          
            • Re: Create Contact using custom delivery channel
              ChewCheeLim

              Thank Mike.

               

              The 1st portion of the code works! However, there is a little glitch when I checked my contact list. For some reason, There is this double AFNotificationContactTemplate objects created for each of contact. Below is my code snippet. Somewhere that I didn't do it right. (I took ur code above and do a 'create contact' logic. )

               

              oSelect = new AFContact(oSystem);

               

                 //add contact into the system

               

                oSelect.Description = "added from core WCF";

               

                 AFNotificationContactTemplate nct = new AFNotificationContactTemplate(oSelect, string.Format("{0} - {1}", txtContactTemplateName.Text, "Email")); 

               

                nct.DeliveryChannelPlugIn = oSystem.DeliveryChannelPlugIns[new Guid(DeliveryChannelGUIDs.Email)];

               

               

                • Re: Create Contact using custom delivery channel
                  ChewCheeLim

                  FYI, The above code didn't use my custom delivery channel yet. I wanted to make sure it's working with existing delivery channel.

                    • Re: Create Contact using custom delivery channel
                      Mike Zboray

                      Yea so I thought you would be using a custom delivery channel where you knew the endpoints would not exist. The UI will auto-create Email endpoints for you. If you want this to work correctly for Email you will have to do two things.

                      1) Find the notification contact templates for the contact first and check that you don't already have an nct for Email. Use AFNotificationContactTemplate.FindNotificationContactTemplatesByContact

                      2) When you create the AFNotificationContactTemplate you have to set the IsInternal property to true. If the UI finds an email endpoint that has IsInternal set to true it will not auto-create an endpoint.

                       

                      Also, you do not have to create an AFContact for an AFNotificationContactTemplate. You can just use the other constructor and it will appear under the DeliveryEndpoints node in the tree. This is typically useful for endpoints that don't represent actual users.

                        • Re: Create Contact using custom delivery channel
                          ChewCheeLim

                          Thanks Mike.

                          The disconnection that I have right now is --> the 'Chew Chee Lim -Email' nct will be auto created by the SDK behind the scene. So if I named my new contact 'Mike Zboray', then cnt = 'Mike Zboray-Email' will be created behind the scene even though I tried to do a Find, I won't be able to find it before hand. Hence there is no way to set the IsInternal = true. Sorry a little slow here.

                           

                           

                           

                            • Re: Create Contact using custom delivery channel
                              Mike Zboray

                              The NCT is auto-created by PSE not the SDK. To prevent auto-creation:

                               

                              If you create a new contact then there obviously is no NCT for it already, and you have to create the NCT, set the delivery channel to Email, and set IsInternal to true.

                               

                              If the contact already exists you should attempt to find its NCTs and see if there is already an NCT with email delivery channel setup. If there is one and IsInternal is not true, you can set its IsInternal to true to prevent the auto-creation. If there isn't you create the NCT, set the delivery channel to Email, and set IsInternal to true.

                               

                              I'm not sure what the image is supposed to be showing me. There are two email ncts for V1090: V1090 - Email and V1090_Email.

                               

                              There is a bug in the PSE UI that shows the auto-generated name as V1090 - Email but the name is really V1090_Email. I believe the UI will actually edit the NCT's name when you click on it, and sets it to the format "{Contact} - {DeliveryChannelName}"

                               

                              Again this is not going to be an issue for your custom delivery channel, so I wouldn't actually spend a lot of time trying to prevent auto-creation for email in the UI.

                                • Re: Create Contact using custom delivery channel
                                  ChewCheeLim

                                  Thanks Mike, in my case, it will always be creating new contacts.

                                  If there is a bug in PSE, then it explains why I am seeing double entries even though I played with diff versions of Logic. The Email cnt won't be able to turn off.

                                   

                                  My test code:- forcefully turning off the email cnt.

                                    oSelect = new AFContact(oSystem);

                                   

                                     //add contact into the system

                                   

                                    oSelect.Description = "added from core WCF";

                                   

                                     AFNotificationContactTemplate nctDefaultEmail = new AFNotificationContactTemplate(oSelect, string.Format("{0} - {1}", txtContactTemplateName.Text, "Email"));

                                   

                                    nctDefaultEmail.DeliveryChannelPlugIn = oSystem.DeliveryChannelPlugIns[new Guid(DeliveryChannelGUIDs.Email)];

                                   

                                    nctDefaultEmail.IsInternal = true;

                                    

                                   

                                       nctDefaultEmail.CheckIn();

                                   

                                     AFNotificationContactTemplate nctCustom = new AFNotificationContactTemplate(oSelect, string.Format("{0} - {1}", txtContactTemplateName.Text, "EMEmail"));

                                   

                                    nctCustom.DeliveryChannelPlugIn = oSystem.DeliveryChannelPlugIns[new Guid("5781bf6b-90e4-4c7b-ac29-d68864b18b36")];

                                   

                                    nctCustom.IsInternal = false;

                                   

                                   

                                      nctCustom.CheckIn();

                                   

                                  But this is the result in PSE.