CampusNexus CRM iServices Help
BeginReply, BuildReply, and SaveReply Methods |
Sample Code on the usage of the BeginReply, BuildReply, and SaveReply methods of CampusNexus CRM Interaction iService.
The following sample illustrates composing a draft reply to an existing Interaction and sending an e-mail message using BeginReply, BuildReply, and SaveReply.
Additionally, this sample illustrates the usage of including a User Signature to the message of an Interaction.
Sample Code for BeginReply, BuildReply, and SaveReply Methods
public void ReplyInteractionSample() { //Creating an Instance of the Interaction iService InteractionWebService interactionService = new InteractionWebService(); //Generating the Username Token Information UsernameToken userToken = getUserToken("ParkerRoy", "password"); //Associating the Username Token with the Interaction iService Instance interactionService.RequestSoapContext.Security.Tokens.Add(userToken); interactionService.RequireMtom = false; long interactionID = 51; //ID of the Interaction //Declaring the output parameters long replyID = -1; string lockedByUser = ""; long originalMessageID = -1; long outgoingMessageID = -1; string error = ""; long result = 0; long[] cachedTeam = null; long interactionTeamID = -1; ReplyInfo replySettings = null; ReplyMsg replyInProgressMsg = null; ReplyMsg originalMessage = null; InteractionInfo interactionDetails = null; long eventID = -1; int aliasID = 1;//Alias ID used for reply long userID = 1155;//ID of the Talisma User who is replying to the Interaction //Calling the BeginReply Method and storing the result in a variable result = interactionService.BeginReply(interactionID, ref replyID, out lockedByUser, out originalMessageID, out outgoingMessageID, out error); if (result != 0) { //Handle Error return; } if (!String.IsNullOrEmpty(lockedByUser)) { long userLock = Convert.ToInt64(lockedByUser.Split(Convert.ToChar(177))[0]); if (userLock != userID) { //Locked by someone else //Handle Lock } } //Fetching the current message details from the Interaction result = interactionService.BuildReply(userID, interactionID, cachedTeam, ref interactionTeamID, ref replyID, out replySettings, out replyInProgressMsg, out originalMessage, out interactionDetails, out error); if (result != 0) { //Handle Error return; } string SubjectPrefix = ""; //Identify the reply prefix from Interaction language that will be prefixed in the Subject foreach (PrefixOptions preFixOption in replySettings.prefixOptions) { if (preFixOption.languageId == 1033/*English (United States) */) { SubjectPrefix = preFixOption.prefixForReply; break; } } //Prepare the recipient list. ReplyAddresses replyRecipientDetails = new ReplyAddresses(); replyRecipientDetails.to = interactionDetails.contactEmail; string FormattedInteractionID = interactionID.ToString("000-###"); //for Interaction ID considered in sample for keeping the behavior consistent with Tailsma Client string userSignaturePlain = ""; string userSignatureHTML = ""; //Retrieving the User Signature of the Talisma User belonging to a Team if(replySettings !=null && replySettings.signatureOptions!=null) { foreach(UserSignature signature in replySettings.signatureOptions) { if (interactionTeamID == signature.teamId && signature.userId==userID) { userSignaturePlain = signature.signaturePlainTextFormat; userSignatureHTML = signature.signatureHtmlFormat ; } } } ReplyMessage replyFinalMessage = new ReplyMessage(); replyFinalMessage.subject = "'" + replySettings.globalConfigOptions.talismaInstallationId + "=" + FormattedInteractionID + "' " + interactionDetails.subject; replyFinalMessage.subjectPrefix = SubjectPrefix; replyFinalMessage.fullMessageContents = @"<html> <body> Hi John, <p>We got to know that you are interested to apply for the Visual Arts course in your university. Attached is a pdf document with details of the Visual Arts program for your reference.</p> <br> <p>Thanks,</p> <br> <p>Agatha</p> <p>" + userSignaturePlain + @"</p> <p> </body> </html>"; replyFinalMessage.partialMessageContents = @"<html> <body> Hi John, <p>We got to know that you are interested to apply for the Visual Arts course in your university. Attached is a pdf document with details of the Visual Arts program for your reference.</p> <br> <p>Thanks,</p> <br> <p>Agatha</p> <p>" + userSignaturePlain + @"</p> <p> </body> </html>"; bool bSend = false; /* Send is not done as this is draft. Send will be done in the second iteration*/ //Saving the draft of changes which will later be modified. result = interactionService.SaveReply(interactionID, replyFinalMessage, replyRecipientDetails, bSend, ref outgoingMessageID, ref eventID, false/*Unlock*/, false /*Resolve Interaction*/ , aliasID, true/*Talisma Signature*/, 0 /*Reply*/, replyInProgressMsg.languageId, false /*Review Reply*/, ""/*CR List */, "" /*SMS Extractor*/, -1 /*SMS Extractor*/, out error); if (result != 0) { //Handle Error return; } ReplyInfo replySettingsCached = replySettings; cachedTeam = new long[] { 53 }; //Fetching the current message details from Interaction for modification. result = interactionService.BuildReply(userID, interactionID, cachedTeam, ref interactionTeamID, ref replyID, out replySettings, out replyInProgressMsg, out originalMessage, out interactionDetails, out error); if (result != 0) { //Handle Error return; } SubjectPrefix = ""; //Identify the reply prefix from interaction language foreach (PrefixOptions preFixOption in replySettingsCached.prefixOptions) { if (preFixOption.languageId == replyInProgressMsg.languageId) { SubjectPrefix = preFixOption.prefixForReply; break; } } //Prepare the recipient list. replyRecipientDetails = new ReplyAddresses(); replyRecipientDetails.to = interactionDetails.contactEmail; FormattedInteractionID = interactionID.ToString("000-###");//for Interaction ID considered in sample for keeping the behavior consistent with Tailsma Client replyFinalMessage = new ReplyMessage(); //Specifying a format for the Subject of the Interaction replyFinalMessage.subject = "'" + replySettingsCached.globalConfigOptions.talismaInstallationId + "=" + FormattedInteractionID + "' " + interactionDetails.subject; replyFinalMessage.subjectPrefix = SubjectPrefix; replyFinalMessage.fullMessageContents = @"<html> <body> Hi John, <p>We got to know that you are interested to apply for the Visual Arts course in your university. Attached is a pdf document with details of the Visual Arts program for your reference.</p> <p>Let us know if you need more information.</p> <br> <p>Thanks,</p> <br> <p>Agatha</p> <p>" + userSignaturePlain + @"</p> <p> </body> </html>"; replyFinalMessage.partialMessageContents = @"<html> <body> Hi John, <p>We got to know that you are interested to apply for the Visual Arts course in your university. Attached is a pdf document with details of the Visual Arts program for your reference.</p> <p>Let us know if you need more information.</p> <br> <p>Thanks,</p> <br> <p>Agatha</p> <p>" + userSignaturePlain + @"</p> <p> </body> </html>"; //Attaching the file for Course details replyFinalMessage.AttachmentArray = new InteractionAttachmentData[1]; replyFinalMessage.AttachmentArray[0] = new InteractionAttachmentData(); replyFinalMessage.AttachmentArray[0].fileBlob = System.IO.File.ReadAllBytes(@"D:/Upload/CourseDetails.pdf"); replyFinalMessage.AttachmentArray[0].fileName = "CourseDetails"; replyFinalMessage.AttachmentArray[0].isNewAttachment = true; replyFinalMessage.AttachmentArray[0].cId = ""; bSend = true; //Mail will be sent out. result = interactionService.SaveReply(interactionID, replyFinalMessage, replyRecipientDetails, bSend, ref outgoingMessageID, ref eventID, false/*Unlock*/, false /*Resolve Interaction*/ , aliasID, true/*Talisma Signature*/, 0 /*Reply*/, replyInProgressMsg.languageId, false /*Review Reply*/, ""/*CR List */, "" /*SMS Extractor*/, -1 /*SMS Extractor*/, out error); if (result != 0) { //Handle Error } }