Telegram integration tutorial
The Telegram Integration for Tiledesk allows to expand the offer of customer service through the exchange of messages between Telegram and Tiledesk support. This integration allows you to connect your company's Telegram bot to your Tiledesk account, thus creating a tunnel between the two platforms. Therefore customers can reach your support simply by writing to your Telegram bot and these messages will be delivered to the Tiledesk webchat, along with messages from other channels. Your agents will have a single work environment.
The following are the steps involved in our tutorial:
- 1.Create a Tiledesk Project
- 2.Create a Telegram Bot
- 3.Configure the Webhook
- 4.Set the Webhook endpoint for Telegram
- 5.Subscribe to a Webhook on Tiledesk
- 6.Test the integration
Create a new project
Now choose a name for your project (i.e. Telegram Tutorial) and click the "CREATE PROJECT" button (leave all the options on their default values).
Choose the project name
Nice, your project is ready.
Now type /newbot to create a new bot or choose from the options proposed by the bot.
So, choose a name for your bot and a username also, following the instruction given by @BotFather.
New telegram bot
Your bot is now operative. Do you see the token? We will need it shortly.
We use the Replit service to fast create our own NodeJS web application endpoint. Fork the tutorial application, available at this url: https://replit.com/@GiovanniTroisi/tiledesk-telegram-tutorial-app.
Use the fork button and choose a name for your app.
Fork Replit project
The app is forked and ready to run.
Now move back to your Tiledesk project's Settings > Project Settings > General section and copy the Project Id
Tiledesk Project Id
Paste the Project Id in the index.js file of your NodeJS app on Replit, as shown in figure:
Paste Project Id
Now move back (again) to your Tiledesk project's Settings > Project Settings > Developer section. We will generate a new secret key that will be used to sign your JWT token. Press "GENERATE SHARED SECRET" button, but note that every time you generate a new secret the previous one will be no longer valid and you have to replace wherever you used it. Then click on "GENERATE".
That's your shared secret key, click on "Copy".
Copy Shared Secret
Paste the Secret Key in the index.js file of your NodeJS app on Replit, as shown in figure:
Paste Shared Secret
Now it's time to use the token provided by @BotFather earlier. Copy and paste it in the index.js file of your NodeJS app on Replit, as shown in figure:
Paste Telegram token
In the same file we need to set also the webhook endpoint for Telegram, that is the endpoint related to your webhook to which Telegram will send messages.
Click on "Run" button to start the server, then copy the URL in the red circle in index.js, inside the function setWebhookEndpoint(), adding "/telegram" at the end of the URL, like in figure:
We almost done, the last thing to do is to add a subscription for Tiledesk. Let's go!
Move to your Tiledesk project's Settings > Project Settings > Developer and click on the "MANAGE WEBHOOK" button.
Manage Webhook Button
Then click on "ADD SUBSCRIPTION" button.
In the New Subscription popup select the Message Create (only for Telegram channel) option from the dropdown and type the Webhook Target that is the same URL than before, adding "/tiledesk" at the end of the URL, like in figure:
Create subscription configuration
Now click on "CREATE SUBSCRIPTION" button.
What you will see next will be the secret associated with your webhook. Keep the secret to interact with webhook trough webhook’s APIs (see here). We don't need it for our goal, but save it in a safe place because it will only be displayed once.
Well, the Webhook is now configured!
Finally we can test the Telegram integration. Move to Telegram app and search the bot created later (search it for name or username or just click on the link present on @BotFather). Then click on "Start".
Start conversation on Telegram
A default message "/start" will be sent to Tiledesk webchat and an agent can now reply.
Message sent from Tiledesk will be delivered in the Telegram Bot chat, like any other conversation.
Done! The integration is completed.
See you on our next tutorial!