To send and receive messages to/from telegram bot natively with MS SQL server (by stored procedures)
- SQL Server 2016 or higher
- Registered Telegram bot check here via Bot Father
- Clone repo
git clone https://github.com/gleberof/SQL-telegram-bot.git
- Run setup.sql (new DB [telegram] with all nesessary procedures will be created)
- Send a message to your bot directly in Telegram (it will help to identify your chat ID). If you're going to use the bot within a group - you need to set up the bot as one of the admins of that group.
- Open
Configure.sql
. Set bot_token given by Bot Father. It will automatically assign chat_id from the last message to the bot or chat. - Run
Jobs.sql
- to enable jobs (it's checking reuests to bot automatically) - To be able to run SELECT and you need to authorize you account with bot:
- Find your bot in telegram or open the chat channel where the bot already added
- Send the
/request_access@[your_bot_name]
command to bot - it's add your telegram ID to usesr table - Open telegram.dbo.users table and find your nickname and set flag [authorized] to 1
- Now you can do selects with bot
- Send a message from SQL by
EXEC [dbo].[usp_SendMessage] @message = N'Hello World!'
- Setup commands.
Please check [telegram].[dbo].[commands]
table to learn how to configure new commands (we setup few during initial setup)
- Setup progress bar for backups. It's almost confugured and run by job (please try backup on you server)
- Execute SQL selects. It's almost ready to execute commands - put
*
symbol before select.
- Setup monitoring. Please check
[telegram].[monitor].[threshold]
to change threshold for alerts
Please do not hesitate to address us in case of questions if any:
- gleberof @ gmail.com
- efremovfedorofficial @ gmail.com