Skip to content

Commit 09e18a3

Browse files
committed
Add dice usage example to EchoBot.
1 parent c79f9fd commit 09e18a3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# F[Tg] - Telegramium
22

3-
[![Telegram](https://img.shields.io/badge/Telegram%20Bot%20API-4.6%20(January%2023%2C%202020)-blue)](https://core.telegram.org/bots/api#recent-changes)
3+
[![Telegram](https://img.shields.io/badge/Telegram%20Bot%20API-4.7%20(March%2030%2C%202020)-blue)](https://core.telegram.org/bots/api#recent-changes)
44

55

66
F[Tg] is a pure functional Telegram Bot API for scala.
@@ -46,6 +46,10 @@ You may also want to have a look at these projects:
4646
* https://github.com/bot4s/telegram
4747
* https://github.com/paoloboni/telegram4s
4848

49+
### Known usages
50+
51+
* https://github.com/oybek/playcs_bot : telegram chat bot for creating counter strike 1.6 dedicated servers
52+
4953
### Note for Yan
5054

5155
Yan, напиши бота.

telegramium-examples/src/main/scala/telegramium/bots/examples/EchoBot.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ class EchoBot[F[_]](bot: Api[F])(implicit syncF: Sync[F], timer: Timer[F]) exten
2727
InlineKeyboardButton("Yes", callbackData = Some("Yes")),
2828
InlineKeyboardButton("No", callbackData = Some("No"))
2929
),
30+
List(
31+
InlineKeyboardButton("Roll the dice", callbackData = Some("dice")),
32+
),
3033
)
3134
)
3235
)
3336
)).void
3437
}
3538

3639
override def onCallbackQuery(query: CallbackQuery): F[Unit] = {
40+
def rollTheDice(chatId: Long): F[Unit] = {
41+
bot.sendDice(SendDiceReq(ChatIntId(chatId))).void >>
42+
bot.answerCallbackQuery(AnswerCallbackQueryReq(callbackQueryId = query.id)).void
43+
}
3744
def sendMsg(chatId: Long, text: String, parseMode: ParseMode): F[Unit] = {
3845
bot.sendMessage(SendMessageReq(
3946
chatId = ChatIntId(chatId),
@@ -45,6 +52,7 @@ class EchoBot[F[_]](bot: Api[F])(implicit syncF: Sync[F], timer: Timer[F]) exten
4552
case "HTML" => query.message.fold(syncF.unit)(m => sendMsg(m.chat.id, htmlText, Html))
4653
case "Markdown" => query.message.fold(syncF.unit)(m => sendMsg(m.chat.id, markdownText, Markdown))
4754
case "Markdown2" => query.message.fold(syncF.unit)(m => sendMsg(m.chat.id, markdown2Text, Markdown2))
55+
case "dice" => query.message.fold(syncF.unit)(m => rollTheDice(m.chat.id))
4856
case x => bot.answerCallbackQuery(AnswerCallbackQueryReq(
4957
callbackQueryId = query.id,
5058
text = Some(s"Your choice is $x")

0 commit comments

Comments
 (0)