The backend for a simple Telegram Bot that generates random strings of any length
A diagram of how Linx, the Telegram API and a Messenger app will interact
- Download and install the Linx Designer https://linx.software/download-linx/
- Pull the Linx 6 Solution folder from this repo
- Sign up for a free Linx Trial Server https://linx.software/pricing/
- Install the Telegram Messenger on your phone (iPhone or Android)
- Go to the @Botfather channel in your Telegram Messenger app (https://telegram.me/BotFather)
- Click ‘Start’
- Send /newbot
- Enter a name for your bot
- Enter a username
- Send /token to get your bot token
- In the Linx Designer, open the TelegramBot.solution file in the repo folder
- Open the solution Settings by clicking the Settings button in the Linx Designer top toolbar
- Locate the TelegramToken setting and paste the token you received from Telegram in the value field
- Check the email you received when signing up to the Linx Server Trial. Here you can find the name in the server URL (for example, in this url https://scqcpc33.linx.twenty57.net the server name is ‘scqcp33’). In the value field of the APIBaseUri setting, replace the xxx (https://xxx.api.linx.twenty57.net/) with the name of your server.
- Register the Webhook by running the SetWebhook function in the Linx Designer
- Open the Telegram and WebHookUtils folders in the Linx solution
- Right-click on the SetWebhook function and select Debug
- Click Start to execute the function. The Debug Output panel should show ‘Function started’ and ‘Function finished’
- Now deploy the solution to your Linx Server by clicking the Deploy button in the Linx Designer
- Add your server in the deploy popup (as per the server email you received)
- Hit the Deploy & Open Server button. The server will open in a browser window when the upload is done.
- Log into your server using the credentials from your trial server email
- Click on the TelegramBot solution
- Select the Settings menu item in the left-hand menu and change the value for APIBaseUrl to: https://+:8080/
- Select the Services menu item in the left-hand menu and switch on the service
You are done setting up your bot in Linx.
Now open your bot in your Telegram Messenger and try it out!
Your bot will respond to any of the commands built into the ‘ProcessMessage’ function in the ‘Service’ folder of the TelegramBot solution.
- /start
- /help
- /random or /random12
You can add more commands by selecting the ‘HandleCommands’ component in the ‘ProcessMessage’ function and selecting the [...] button on the ‘Conditions’ property.
The ‘HandleCommands’ component represents an If/Else statement. You can add a new condition to the list. This will provide you with an execution path, like the paths for start, help and random where you can define what you want to do when the condition is met.