Created
August 1, 2019 00:43
-
-
Save pintowar/afb58e2f5a2def148cb53c773b42b2c4 to your computer and use it in GitHub Desktop.
Minimalist telegram chat bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Grab('com.github.pengrad:java-telegram-bot-api:4.4.0') | |
| import com.pengrad.telegrambot.TelegramBot | |
| import com.pengrad.telegrambot.UpdatesListener | |
| import com.pengrad.telegrambot.request.SendMessage | |
| def bot = new TelegramBot("my:token") //token | |
| def chats = [] as Set //chatIds as Long | |
| bot.setUpdatesListener { updates -> | |
| // ... process updates | |
| // return id of last processed update or confirm them all | |
| //chat=Chat{id=108569910 | |
| chats += (updates.collect { it.message().chat().id() } as Set) | |
| chats.each { chatId -> | |
| println "To chat $chatId" | |
| sendMessage(bot, chatId, 'Hello Master!!') | |
| } | |
| return UpdatesListener.CONFIRMED_UPDATES_ALL; | |
| } | |
| def sendMessage(TelegramBot bot, Long chatId, message) { | |
| def request = new SendMessage(chatId, message) | |
| bot.execute(request) | |
| } | |
| println "Waiting..." | |
| synchronized (this) { this.wait() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment