As we all know that BOTs are the most buzz topic now-a-days and Telegram messaging application has a good hold
on it as a platform. Recently we received a couple of feedback from our customers to integrate some messaging
application with Dynamics NAV because that’s where they work-in the whole day and they don’t like to switch the screen to connect with their co-workers. We had been searching a good BOT to integrate with our ERP until we ended up crafting it on Telegram. It’s very easy and fun work.
Easiest Steps to Integrate Telegram with Microsoft Dynamics NAV
- Connect to @BotFather account of Telegram by searching like this
2. Create new bot by sending /newBot command
3. It will ask for your Bot name that you want to create.
4. Give Suitable name that ends with for Ex: NAV_bot.
5. Each bot is given a unique authentication token when it is created. The token looks something like 326076132:AAEufsce4s2sg5b6mdbmW_KLTcbmS-HeVXY.
- To generate token, just go into botFather account.
- Send /token
- It will ask you that, for which bot you want to generate token.
- Just Tap on our newly created bot name @Navision_bot.
- That’s it, just copy this token for your reference.
6. Now, I have created this bot to Integrate with NAVISION, so for that you require to generate Chat IDs of users to send chat messages to any Telegram User.
- First of all, users will have to send test message to the BOT that you created.
- For that, search your bot account in Telegram starts with @ Sign followed by your Bot Name.
- Just enter into your bot, and type /Start to send test message to generate your Chat ID.
- Now, your Chat ID generated and you will get it by calling getUpdates method of Telegram API, for this you have to call getUpdates method in web browser as follows.
- https://api.telegram.org/bot<Your Bot Name>/getUpdates
- For Ex: https://api.telegram.org/324480200:AAGxuzqskveyV-ZBTM81P0CCI2qartfWPfo/getUpdates
- You will see the response of telegram in JSON format as follows.
- From here you can get the Chat IDs.
7. All set, now you can send message to any user. And it will have sent from your newly created
- To Integrate Telegram with NAV, we have focused to send requests via CURL tool, that silently run HTTP requests from
- For Ex:
- Open CMD.
- Go to the path where your CURL tool is there.
- Run the command to send Http Post request like this: Curl -X POST “https://api.telegram.org/bot326076132:AAEufscs4s2sg5b6mEbmW_KLTcbmS-HeVXY/sendMessage” -d “chat_id=163898670&text=my sample text”
All Above Steps are to test sample message sending from HTTP request.
8. Now to Integrate Telegram with NAV, you will have to send HTTP requests from NAV code, For that, I have used CURL tool that run silently from your PC and sends HTTP request.
9. Create One Automation variable of ‘Windows Script Host Object Model’.WshShell to open CMD and run CURL command.
10. Here are some sample commands to send messages and send attachments from NAV.
- curl -X POST “https://api.telegram.org/bot326076132:AAEufccs4s2kg5b6mfbmW_KLTcbmS-HeVXY/sendMessage” -d “chat_id=-189801512&text=my sample text”
- curl -F chat_id=”35065383″ -F document=@”//intechserver/Shared/FTP/Attachments/Temp.pdf” -F caption=”PFA” https://api.telegram.org/bot326076132:AAEufscs4s2sg5b6mEbmW_KLTcbmS-HeVXY/sendDocument
- just run above commands from NAV with the use of Automation variable.
11. Just create Two tables, one is for chat IDs for individual NAV users and another is to create telegram message queue.
- Chat IDs table will contain user ID and Chat ID fields.
- Message queue table will contain User ID of receiver, attachment, Message body fields.
- Now do code for send message Action with the use of above automation variable and CMD command as above.
12. Final NAV will look like this,
This page contains Chat IDs of Individual Users in NAV.
This Page will send Message to particular User that was added in Chat IDs table.
Just place sendMessage code on this Send Message Action
You can keep Sent Message Entries by creating another page like this.
If you need any help, feel free to reach us.