This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Topic Collaboration in FreshDesk
The third use case in the FreshDesk business scenario is topic collaboration, in which you create a topic in FreshDesk, add that as a thread in Disqus in order to retrieve the best post from Disqus so that you can add that best post in FreshDesk. This page describes the relevant tasks and the operations you use in the FreshDesk connector and the other ESB connectors.
Overview
The flow for topic collaboration is illustrated in the following diagram. We will use the ESB connectors for FreshDesk and Disqus to connect to each service.
- In FreshDesk, create a forum topic using createTopic.
- Add the topic as a thread in Disqus using createThread and retrieve the best post from Disqus for the created thread using listPosts.
- In FreshDesk, create the best post using createPost. When you create the best post it replaces the existing best post.
- Delete the replaced post from FreshDesk using deletePost.
FreshDesk operations
Disqus operations
Samples
Sample Proxy to create a topic in FreshDesk
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="freshdesk_createTopicAndThread" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence onError="faultHandlerSeq"> <!--Freshdesk Properties--> <property name="freshdesk.apiUrl" expression="json-eval($.freshdeskApiUrl)" /> <property name="freshdesk.apiKey" expression="json-eval($.freshdeskApiKey)" /> <property name="freshdesk.forumId" expression="json-eval($.freshdeskForumId)" /> <property name="freshdesk.categoryId" expression="json-eval($.freshdeskCategoryId)" /> <property name="freshdesk.title" expression="json-eval($.freshdeskTitle)" /> <property name="freshdesk.bodyHtml" expression="json-eval($.freshdeskBodyHtml)" /> <!--Disqus Properties--> <property name="disqus.apiUrl" expression="json-eval($.disqusApiUrl)" /> <property name="disqus.apiKey" expression="json-eval($.disqusApiKey)" /> <property name="disqus.accessToken" expression="json-eval($.disqusAccessToken)" /> <property name="disqus.forumId" expression="json-eval($.disqusForumId)" /> <property name="responseString" value="" scope="operation" /> <!--Create Topic in Freshdesk--> <freshdesk.init> <apiUrl>{$ctx:freshdesk.apiUrl}</apiUrl> <format>json</format> <apiKey>{$ctx:freshdesk.apiKey}</apiKey> </freshdesk.init> <freshdesk.createTopic> <forumId>{$ctx:freshdesk.forumId}</forumId> <categoryId>{$ctx:freshdesk.categoryId}</categoryId> <title>{$ctx:freshdesk.title}</title> <bodyHtml>{$ctx:freshdesk.bodyHtml}</bodyHtml> <sticky>0</sticky> <locked>false</locked> </freshdesk.createTopic> <sequence key="removeResponseHeaders" /> <property name="freshdesk.topicId" expression="json-eval($.topic.id)" /> <!--If the createTopic method of Freshdesk fails, return an error message and terminate the scenario. --> <filter source="boolean(get-property('freshdesk.topicId'))" regex="false"> <then> <!--Since there is no ID to be returned, the id is set to empty JSON object - {}--> <property name="id" value="{}" /> <property name="message" expression="json-eval($)" /> <!--Call the responseHandler template--> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="freshdesk_createTopicInFreshdesk" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="Failed" /> <with-param name="message" value="{$ctx:message}" /> </call-template> <loopback /> </then> <else> <property name="id" expression="fn:concat('freshdesk_topicId:', get-property('freshdesk.topicId'))" /> <property name="message" expression="json-eval($)" /> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="freshdesk_createTopic" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="Success" /> <with-param name="message" value="Topic was successfully created in Freshdesk." /> </call-template> <property name="freshdesk.topicTitle" expression="json-eval($.topic.title)" /> <!--Invalidating the uri.var.categoryId property which was set in the freshdesk.createTopic Template to prevent ambiguity.--> <property name="uri.var.categoryId" action="remove"/> <!--Create Thread in Disqus--> <disqus.init> <apiUrl>{$ctx:disqus.apiUrl}</apiUrl> <apiKey>{$ctx:disqus.apiKey}</apiKey> <accessToken>{$ctx:disqus.accessToken}</accessToken> </disqus.init> <disqus.createThread> <forumId>{$ctx:disqus.forumId}</forumId> <title>{$ctx:freshdesk.title}</title> <message>{$ctx:freshdesk.bodyHtml}</message> </disqus.createThread> <sequence key="removeResponseHeaders" /> <property name="disqus.threadId" expression="json-eval($.response.id)" /> <!--If the Thread CANNOT be created in Disqus, return an error message and terminate the scenario.--> <filter source="boolean(get-property('disqus.threadId'))" regex="false"> <then> <property name="id" expression="fn:concat('freshdesk_topicId:', get-property('freshdesk.topicId'))" /> <property name="message" expression="json-eval($)" /> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="disqus_createNewThreadInDisqus" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="Failed" /> <with-param name="message" value="{$ctx:message}" /> </call-template> <loopback /> </then> <else> <!--Send success message to the User.--> <property name="disqus.threadLink" expression="json-eval($.response.link)" /> <property name="disqus.threadTitle" expression="json-eval($.response.title)" /> <property name="disqus.forum" expression="json-eval($.response.forum)" /> <property name="id" expression="fn:concat('disqus_threadId:', get-property('disqus.threadId'))" /> <property name="message" expression="fn:concat('Thread was successfully created in ', get-property('disqus.forum'), ' forum in Disqus. [Link - ', get-property('disqus.threadLink'), ']')" /> <!--Call the responseHandler template--> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="disqus_createThread" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="Success" /> <with-param name="message" value="{$ctx:message}" /> </call-template> <loopback /> </else> </filter> </else> </filter> </inSequence> <outSequence> <payloadFactory media-type="json"> <format>{ "Response":{ "process":"freshdesk_createTopicAndThread", "activityResponse": [$1] } } </format> <args> <arg expression="get-property('operation','responseString')" /> </args> </payloadFactory> <property name="messageType" value="application/json" scope="axis2" /> <send /> </outSequence> </target> <description /> </proxy>
Sample request to create a topic in FreshDesk
{ "freshdeskApiUrl":"https://scenario.freshdesk.com", "freshdeskApiKey":"BQR7RBSD7ybpPcUAz", "freshdeskForumId":"5000166384", "freshdeskCategoryId":"5000042003", "freshdeskTitle":"What are the new features of Java NIO?", "freshdeskBodyHtml":"What are the new features of Java NIO?", "disqusApiUrl": "https://disqus.com", "disqusApiKey": "hNCiYG7sBpsyavTbpysXNgHKJ8YDb9IFr3LpcVGj3eEZTPCicTJxNBoHub4etovu", "disqusAccessToken": "e208cc08128f480597fdf91cc0708187", "disqusForumId": "canvas-scenario" }
Sample proxy to update the entries of a particular topic in FreshDesk with the top posts from the corresponding thread created in Disqus
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="freshdesk_updateTopicWithTopPosts" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence onError="faultHandlerSeq"> <!--Freshdesk Properties--> <property name="freshdesk.apiUrl" expression="json-eval($.freshdeskApiUrl)" /> <property name="freshdesk.apiKey" expression="json-eval($.freshdeskApiKey)" /> <property name="freshdesk.categoryId" expression="json-eval($.freshdeskCategoryId)" /> <property name="freshdesk.forumId" expression="json-eval($.freshdeskForumId)" /> <!--Disqus Properties--> <property name="disqus.apiUrl" expression="json-eval($.disqusApiUrl)" /> <property name="disqus.apiKey" expression="json-eval($.disqusApiKey)" /> <property name="disqus.topPosts" expression="json-eval($.disqusTopPosts)" /> <property name="disqus.forumId" expression="json-eval($.disqusForumId)" /> <!--Array of ID Map (Freshdesk Topics and Disqus Threads) Objects--> <property name="freshdesk.disqus.idMap" expression="json-eval($.freshdeskDisqusIdMap)" /> <property name="responseString" value="" scope="operation" /> <property name="noOfTopics" expression="count(//jsonObject/freshdeskDisqusIdMap)" scope="operation" /> <property name="topicIndex" expression="0" scope="operation" /> <property name="noOfPosts" expression="0" scope="operation" /> <property name="postIndex" expression="0" scope="operation" /> <!--If the freshdeskDisqusIdMap Array is empty, send an error message to the user and terminate the scenario.--> <filter xpath="get-property('operation', 'noOfTopics') = get-property('operation', 'topicIndex')"> <then> <payloadFactory media-type="json"> <format>{ "Response":{ "activity":"freshdesk_updateTopicsWithTopPosts", "activityResponse":"freshdeskDisqusIdMap is empty - No entries to process." } } </format> </payloadFactory> <property name="messageType" value="application/json" scope="axis2" /> <respond /> </then> <else> <!--FOR EACH TopicID Map - Delete Loop: BEGIN--> <iterate continueParent="false" id="topics" expression="//jsonObject/freshdeskDisqusIdMap" sequential="true"> <target> <sequence> <!--Increment the Topic Count by 1.--> <property name="topicIndex" expression="get-property('operation', 'topicIndex') + 1" scope="operation" /> <!--Store the Topic and Thread Details.--> <property name="freshdesk.topicId" expression="//freshdeskDisqusIdMap/freshdesk_topicId/text()" /> <property name="disqus.threadId" expression="//freshdeskDisqusIdMap/disqus_threadId/text()" /> <!--First check whether there are any featured posts for the Thread in Disqus.--> <disqus.init> <apiUrl>{$ctx:disqus.apiUrl}</apiUrl> <apiKey>{$ctx:disqus.apiKey}</apiKey> </disqus.init> <disqus.listPosts> <forumId>{$ctx:disqus.forumId}</forumId> <limit>{$ctx:disqus.topPosts}</limit> <popular>true</popular> <include>unapproved,approved,highlighted</include> <order>best</order> <related>thread</related> <threadId>{$ctx:disqus.threadId}</threadId> </disqus.listPosts> <sequence key="removeResponseHeaders" /> <property name="noOfPosts" expression="count(//jsonObject/response)" /> <property name="postIndex" expression="0" /> <!--Delete posts if there are any under the topic in FreshDesk.--> <filter xpath="get-property('noOfPosts') != get-property('postIndex')"> <then> <!--Get Freshdesk Topic--> <freshdesk.init> <apiUrl>{$ctx:freshdesk.apiUrl}</apiUrl> <format>json</format> <apiKey>{$ctx:freshdesk.apiKey}</apiKey> </freshdesk.init> <freshdesk.getTopic> <topicId>{$ctx:freshdesk.topicId}</topicId> <categoryId>{$ctx:freshdesk.categoryId}</categoryId> <forumId>{$ctx:freshdesk.forumId}</forumId> </freshdesk.getTopic> <sequence key="removeResponseHeaders" /> <property name="noOfposts" expression="count(//topic/posts)" /> <property name="postIndex" expression="0" /> <!--Delete posts if there are any.--> <filter xpath="get-property('noOfposts') != get-property('postIndex')"> <then> <!--Increment the No. of posts to be deleted by the appropriate No.--> <property name="noOfPosts" expression="get-property('operation','noOfPosts') + count(//topic/posts)" scope="operation" /> <!--FOR EACH Post: BEGIN--> <iterate continueParent="false" id="entries" expression="//topic/posts" sequential="true"> <target> <sequence> <property name="freshdesk.postId" expression="//posts/id/text()" /> <!--Delete the post.--> <freshdesk.init> <apiUrl>{$ctx:freshdesk.apiUrl}</apiUrl> <format>json</format> <apiKey>{$ctx:freshdesk.apiKey}</apiKey> </freshdesk.init> <freshdesk.deletePost> <topicId>{$ctx:freshdesk.topicId}</topicId> <forumId>{$ctx:freshdesk.forumId}</forumId> <categoryId>{$ctx:freshdesk.categoryId}</categoryId> <postId>{$ctx:freshdesk.postId}</postId> </freshdesk.deletePost> <sequence key="removeResponseHeaders" /> <!--Increment the post count.--> <property name="postIndex" expression="get-property('operation','postIndex') + 1" scope="operation" /> </sequence> </target> </iterate> <!--FOR EACH Post: END--> </then> </filter> </then> </filter> </sequence> </target> </iterate> <!--FOR EACH TopicID Map - Delete Loop: END--> <!--Start Adding Posts.--> <filter xpath="(get-property('operation', 'noOfTopics') = get-property('operation', 'topicIndex')) and (get-property('operation', 'noOfPosts') = get-property('operation', 'postIndex'))"> <then> <property name="topicIndex" expression="0" scope="operation" /> <property name="noOfPosts" expression="0" scope="operation" /> <property name="postIndex" expression="0" scope="operation" /> <!--Set the User Payload for iteration.--> <payloadFactory media-type="json"> <format>{ "idmap": $1 } </format> <args> <arg expression="get-property('freshdesk.disqus.idMap')" /> </args> </payloadFactory> <!--FOR EACH TopicID Map: BEGIN--> <iterate continueParent="false" id="discussions" expression="//jsonObject/idmap" sequential="true"> <target> <sequence> <!--Increment the Topic Count.--> <property name="topicIndex" expression="get-property('operation', 'topicIndex') + 1" scope="operation" /> <!--Store the Topic and Thread Details.--> <property name="freshdesk.topicId" expression="//idmap/freshdesk_topicId/text()" /> <property name="disqus.threadId" expression="//idmap/disqus_threadId/text()" /> <!--Invalidate the uri.var.categoryId which was set in the FreshDesk methods to prevent ambiguity.--> <property name="uri.var.categoryId" action="remove" /> <!--List and check whether there are any featured posts for the Thread in Disqus.--> <disqus.init> <apiUrl>{$ctx:disqus.apiUrl}</apiUrl> <apiKey>{$ctx:disqus.apiKey}</apiKey> </disqus.init> <disqus.listPosts> <forumId>{$ctx:disqus.forumId}</forumId> <limit>{$ctx:disqus.topPosts}</limit> <popular>true</popular> <include>unapproved,approved,highlighted</include> <order>best</order> <related>thread</related> <threadId>{$ctx:disqus.threadId}</threadId> </disqus.listPosts> <sequence key="removeResponseHeaders" /> <property name="noOfPosts" expression="count(//jsonObject/response)" /> <property name="postIndex" expression="0" /> <!--If the Thread does not have any posts, send a message to the user.--> <filter xpath="get-property('noOfPosts') = get-property('postIndex')"> <!----> <then> <property name="id" expression="fn:concat('freshdesk_topicId:', get-property('freshdesk.topicId'), ',disqus_threadId:', get-property('disqus.threadId'))" /> <property name="status" value="Empty" /> <property name="message" expression="fn:concat('No posts were found in Disqus for Thread ID: ', get-property('disqus.threadId'))" /> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="disqus_listPopularThreads" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="{$ctx:status}" /> <with-param name="message" value="{$ctx:message}" /> </call-template> </then> <else> <!--Increment the No. of entries to be deleted.--> <property name="noOfPosts" expression="get-property('operation','noOfPosts') + count(//jsonObject/response)" scope="operation" /> <iterate continueParent="false" id="posts" expression="//jsonObject/response" sequential="true"> <target> <sequence> <property name="disqus.post.id" expression="//response/id/text()" /> <property name="disqus.message" expression="//response/raw_message/text()" /> <property name="disqus.commentor" expression="//response/author/name/text()" /> <property name="disqus.likes" expression="//response/points/text()" /> <property name="messageToUpdate" expression="fn:concat(get-property('disqus.message'), ' - ', get-property('disqus.commentor'), ' [', get-property('disqus.likes'), ' Point(s)]')" /> <!--Build the ID String.--> <property name="id" expression="fn:concat('freshdesk_topicId:', get-property('freshdesk.topicId'), ',disqus_threadId:', get-property('disqus.threadId'), ',disqus_postId:', get-property('disqus.post.id'))" /> <!--Create the post.--> <freshdesk.init> <apiUrl>{$ctx:freshdesk.apiUrl}</apiUrl> <format>json</format> <apiKey>{$ctx:freshdesk.apiKey}</apiKey> </freshdesk.init> <freshdesk.createPost> <topicId>{$ctx:freshdesk.topicId}</topicId> <forumId>{$ctx:freshdesk.forumId}</forumId> <categoryId>{$ctx:freshdesk.categoryId}</categoryId> <bodyHtml>{$ctx:messageToUpdate}</bodyHtml> </freshdesk.createPost> <sequence key="removeResponseHeaders" /> <property name="freshdesk.postId" expression="json-eval($.post.id)" /> <!--If creation was unsuccessful, set an error message to be sent to the user.--> <filter source="boolean(get-property('freshdesk.postId'))" regex="true"> <then> <property name="status" value="Success" /> <property name="message" value="Freshdesk topic posts successfully synchronized with Disqus thread posts." /> </then> <else> <property name="status" value="Failure" /> <property name="message" expression="json-eval($)" /> </else> </filter> <!--Call the Response Handler Template.--> <call-template target="responseHandlerTemplate"> <with-param name="activity" value="freshdesk_synchronizeTopDisqusPostsWithFreshdesk" /> <with-param name="id" value="{$ctx:id}" /> <with-param name="status" value="{$ctx:status}" /> <with-param name="message" value="{$ctx:message}" /> </call-template> <!--Increment the post count.--> <property name="postIndex" expression="get-property('operation','postIndex') + 1" scope="operation" /> </sequence> </target> </iterate> </else> </filter> </sequence> </target> </iterate> <!--FOR EACH TopicID Map: END--> <filter xpath="(get-property('operation', 'noOfTopics') = get-property('operation', 'topicIndex')) and (get-property('operation', 'noOfPosts') = get-property('operation', 'postIndex'))"> <then> <loopback /> </then> </filter> </then> </filter> </else> </filter> </inSequence> <outSequence> <payloadFactory media-type="json"> <format>{ "Response":{ "process":"freshdesk_updateTopicsWithTopPosts", "activityResponse":[$1] } } </format> <args> <arg expression="get-property('operation','responseString')" /> </args> </payloadFactory> <property name="messageType" value="application/json" scope="axis2" /> <send /> </outSequence> </target> <description /> </proxy>
Sample request to update the entries of a particular topic in FreshDesk with the top posts from the corresponding thread created in Disqus
{ "freshdeskApiUrl":"https://scenario.freshdesk.com", "freshdeskApiKey":"BQR7RBSD7ybpPcUAz", "freshdeskForumId":"5000166384", "freshdeskCategoryId":"5000042003", "freshdeskDisqusIdMap":[{ "freshdesk_topicId": "5000012034", "disqus_threadId": "3309119691" }], "disqusApiUrl": "https://disqus.com", "disqusApiKey": "hNCiYG7sBpsyavTbpysXNgHKJ8YDb9IFr3LpcVGj3eEZTPCicTJxNBoHub4etovu", "disqusForumId": "canvas-scenario", "disqusTopPosts": 1 }