How a Freshchat Javascript SDK came to be!

Arun Rajkumar
Freshworks Developer Platform Blog
3 min readMar 18, 2021
Photo by Artem Sapegin on Unsplash

The Freshworks development platform includes a serverless environment to enable us to create apps that observe events such as app setup, product events, and external events. Serverless computing involves servers but they are abstracted away from developers.

Node modules in serverless apps

When working with serverless apps, we tend to consume a number of node modules written by other developers.

For example, if we wanted to make API calls, we would use the Axios library by first mentioning it in the app’s manifest.json file and then by requiring it in the server.js file.

Freshchat Javascript SDK

When we built Advanced Automations for Freshchat, we had to consume Freshchat APIs heavily. The module responsible for that was packaged along with the app during fdk pack.

When building other apps that made use of the same set of APIs we found ourselves duplicating code. Soon, we ended up with multiple versions of the same code in different codebases.

We decided to publish the Freshchat Javascript SDK as a node module so that developers can consume the APIs with ease and the codebases are easier to maintain.

@freshworks-jaya/freshchat-api contains convenient methods to access the Freshchat API resources such as Agents, Groups, Conversations, Messages, Conversation Transcripts, and so on.

To work with TypeScript in serverless apps, we can use @freshworks-jaya/marketplace-models to import all the type definitions of Freshchat’s product events.

Some Freshworks apps that are already using these npm packages are Email Transcript, Automated Reports and Historical Reports.

Example: Conversation Transcript

Here is an example of how to use the Freshchat JS SDK to fetch a conversation transcript in HTML.

First, mention your dependencies in the manifest.json file.

Then, require @freshworks-jaya/freshchat-api in the server.js file.

Finally, call the getConversationTranscript API by passing the required parameters.

A success callback, returns the entire conversation as a HTML string, which when rendered appropriately is displayed just as in the Freshchat’s agent facing team Inbox.

We see a growing usage of the getConversationTranscript API among apps built for Freshchat. So hopefully you will find an opportunity to use this too!

Conclusion

If you are building apps for Freshchat that require working with the APIs, you can now get a headstart by building upon these packages we have already used with multiple successful apps.

We would also like to encourage you to modularise your code as we were able to do and publish more npm packages that benefit our wider developer community.

Here are the top three reasons why we should consider publishing npm packages:

  1. We can reuse our own work.
  2. Open-source enables us to give back to the community.
  3. We can independently build, test, and deploy our node modules.

Feel free to connect with me at the forum.

Follow us on Medium to get regular updates on our blogs. You can also reach out to us at the developer community forum for further queries or suggestions.

--

--