-
Notifications
You must be signed in to change notification settings - Fork 17
/
LongPollingExample.kt
56 lines (53 loc) · 1.93 KB
/
LongPollingExample.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import com.elbekd.bot.Bot
import com.elbekd.bot.model.toChatId
import com.elbekd.bot.types.BotCommand
import com.elbekd.bot.types.BotCommandScope
import com.elbekd.bot.types.KeyboardButton
import com.elbekd.bot.types.KeyboardButtonPollType
import com.elbekd.bot.types.ParseMode
import com.elbekd.bot.types.ReplyKeyboardMarkup
fun main() {
val token = "<TOKEN>"
val bot = Bot.createPolling(token)
bot.onCommand("/start") { (msg, _) ->
bot.sendMessage(
chatId = msg.chat.id.toChatId(),
text = "`Hello`",
parseMode = ParseMode.MarkdownV2,
replyMarkup = ReplyKeyboardMarkup(
keyboard = listOf(
listOf(
KeyboardButton(
text = "Button 1",
requestPoll = KeyboardButtonPollType(KeyboardButtonPollType.Type.Any)
),
KeyboardButton(
text = "Button 2",
requestPoll = KeyboardButtonPollType(KeyboardButtonPollType.Type.Regular)
)
),
listOf(
KeyboardButton(
text = "Button 3",
requestPoll = KeyboardButtonPollType(KeyboardButtonPollType.Type.Quiz)
)
)
),
inputFieldPlaceholder = "this is place holder"
)
)
}
bot.onCommand("/stop") { (msg, _) ->
val button = bot.getChatMenuButton(msg.chat.id)
bot.sendMessage(msg.chat.id.toChatId(), "$button")
bot.setMyCommands(
commands = listOf(
BotCommand(
command = "/start", description = "this is start"
)
),
scope = BotCommandScope.BotCommandScopeAllGroupChats
)
}
bot.start()
}