Telegram integration tutorial
Introduction
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F175036688-f26d0efe-3150-425b-bab2-6ca07b63adf6.png&width=768&dpr=4&quality=100&sign=27740c85&sv=1)
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.
Steps
The following are the steps involved in our tutorial:
Create a Tiledesk Project
Create a Telegram Bot
Configure the Webhook
Set the Webhook endpoint for Telegram
Subscribe to a Webhook on Tiledesk
Test the integration
Create a Tiledesk Project
First of all create a Tiledesk project. Log in to the Tiledesk Console, then click on "Add project".
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174244101-5d096a58-857d-45e2-9311-bca7c05063bf.png&width=768&dpr=4&quality=100&sign=71b22527&sv=1)
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).
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F175033347-d45427f5-6654-420e-a1da-f77fba15ab1b.png&width=768&dpr=4&quality=100&sign=cbe46bab&sv=1)
Nice, your project is ready.
Create a Telegram Bot
Well, let's move on the Telegram app, on the desktop version or on the mobile one. Search and start the conversation with @BotFather.
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.
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174252867-0c159500-2937-4a50-9993-d11226fbc9af.png&width=768&dpr=4&quality=100&sign=27e5626a&sv=1)
Your bot is now operative. Do you see the token? We will need it shortly.
Configure the Webhook
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.
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174968675-5813f440-a39f-4af8-8a3d-10596e117e98.png&width=768&dpr=4&quality=100&sign=17dba450&sv=1)
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
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174268648-d3f28bab-67aa-4683-93d3-8de33e97a324.png&width=768&dpr=4&quality=100&sign=bf13e95a&sv=1)
Paste the Project Id in the index.js file of your NodeJS app on Replit, as shown in figure:
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174282279-1c069dc4-02cf-4597-9002-74c4f7650440.png&width=768&dpr=4&quality=100&sign=4f03110e&sv=1)
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".
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174272766-a397b947-2cca-4f5d-99b1-53efe6ff96b9.png&width=768&dpr=4&quality=100&sign=71fbb8c4&sv=1)
That's your shared secret key, click on "Copy".
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174273202-104b99fe-c790-4081-b60a-d843b9554eca.png&width=768&dpr=4&quality=100&sign=be8de2e5&sv=1)
Paste the Secret Key in the index.js file of your NodeJS app on Replit, as shown in figure:
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174282285-f2720cc6-91f6-4f51-9974-18140edb3df8.png&width=768&dpr=4&quality=100&sign=326cd706&sv=1)
Set the Webhook endpoint for Telegram
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:
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F175038765-04233d8b-a05f-452c-95f5-4dc8c6f2bda1.png&width=768&dpr=4&quality=100&sign=f789d8e8&sv=1)
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:
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174815348-e1dfb890-aec4-4640-acb8-100a9f545935.png&width=768&dpr=4&quality=100&sign=12bca8a&sv=1)
Subscribe to a Webhook on Tiledesk
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.
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174817082-e01011ae-8977-42e8-a10d-53dd21b1e5c5.png&width=768&dpr=4&quality=100&sign=4b82c26d&sv=1)
Then click on "ADD SUBSCRIPTION" button.
![](https://developer.tiledesk.com/~gitbook/image?url=https%3A%2F%2Fuser-images.githubusercontent.com%2F45603238%2F174286884-5a229142-cef0-4be8-8e5f-418b3568586e.png&width=768&dpr=4&quality=100&sign=7590ef93&sv=1)
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:
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!
Test the integration
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".
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.
Here you can find an example code to integrate with Twilio (WhatsApp) based on the same principles treated in this tutorial
And here, another one example code, this time for Facebook Messenger integration.
If you have any problems do not esitate to write us on our Community forum!
See you on our next tutorial!
Do you have suggestions on this article? Please send us your feedback writing an email to info@tiledesk.com
Last updated