Building a Notification System for Freshservice through Marketplace apps

Mino De Raj
4 min readJun 4, 2022

--

The goal of this writeup is to introduce you to the power of integrations and provide a real-time sample of how we achieved it through a simple Freshservice Marketplace app.

Notifications

Freshservice is a service management product with capabilities to integrate with a wide range of third-party applications.

Telegram is an Instant Messaging Service that is end-to-end encrypted and used by many users across the globe.

In generic terms, integration is the ability of products to communicate with each other thereby extending their inherent capabilities. Integrations speak the language of APIs.

Freshservice - Telegram Integration

Let’s consider a simple use case: Whenever a ticket is created in Freshservice, a notification (as an Instant Message) should be sent to an appropriate Telegram user. This should ideally help in faster resolution. We can ten to this use case through a Freshservice — Telegram integration facilitated through a Marketplace app.

Architecture

Freshservice <-> Telegram integration Architecture

Freshservice provides product events that are triggered whenever an action such as creating a new ticket, updating a ticket’s properties such as priority, status, agent and so on are performed in Freshservice.

A Marketplace app can subscribe to these events and perform subsequent actions such as making API calls. In our scenario, when a new ticket is created, the onTicketCreate event is triggered. The corresponding event handler can send a notification to a particular user.

What do we need to get started?

From Telegram:
-
Chat Id of the user you wish to send the updates to.
- Telegram Bot Token

Telegram APIs:
We’re going to use only one API to communicate from Freshservice to Telegram. The API endpoint is as follows

https://api.telegram.org/bot<Bot-Token>/sendMessage?chat_id=<Chat-Id>&text=<Text to be sent>

Let’s call our Freshservice Marketplace app as FreshNotifyBot:

App Code
The following is the file structure of any marketplace app. You can get more information on how to create an app from scratch and an explanation of all the files here.
From the perspective of FreshNotifyBot, let us take a closer look at iparams.json, manifest.json, and server.js(where the core app logic lies)

FreshNotifyBot File structure

iparams.json

We have configured two parameters — chatId and the telegramBotKey as the input fields on the app’s settings page.

manifest.json

manifest.json

This file contains the dependencies, domains to be whitelisted, and the events that the app subscribes to. For the current use case, we have used only one event, onTicketCreate. This event is generated whenever a ticket is created in Freshservice. We have also whitelisted https://api.telegram.org as this is the API endpoint that the app calls.

Note: node, platform-version, and fdk are subject to change as newer versions of the fdk are released.

server.js

server.js

This is the file in which most of our business logic is present.
Lines 4–7: We define the events for which we need a callback and the corresponding callback function.

Lines 9–20: The onTicketCreateHandler is the callback function that is called when the onTicketCreate event trigger is received. Here, we have the core business logic to send a Telegram message via an API. We send the tickets subject to the users’ telegram. $request.post will send the API request to telegram.

You can find the code at https://github.com/MinoDe/FS-Telegram-Notify-Bot

Next Steps

Now that we’ve got a fair idea of how things are working, let’s take it up a notch. The notifications might be too noisy if we send a message for every new ticket. So, we can use two events and send notifications only if the ticket is assigned to a particular agent.
In this case we use the onTicketCreate and onTicketUpdate events.

Future Enhancements

The above use-case can be enhanced with some basic understanding of how bots work. We can build more functionalities such as replying to a telegram message and adding a reply/note in Freshservice. The status of the Frehservice tickets can be changed based on commands from Telegram. This opens the gate to a wide array of possibilities and thus explains why integrations are a powerful weapon.

Further Readings

Go ahead, build your app and have fun developing with Freshservice.

--

--