Skip to content

Commit d3a6576

Browse files
committed
Bot API 4.8
1 parent 3347405 commit d3a6576

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

examples/echo_bot.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ addHandler(L)
77
const API_KEY = slurp("secret.key").strip()
88

99
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async.} =
10-
if not u.message.isSome:
10+
if not u.message:
1111
return true
1212
var response = u.message.get
13-
if response.text.isSome:
13+
if response.text:
1414
let text = response.text.get
1515
discard await b.sendMessage(response.chat.id, text, parseMode = "markdown", disableNotification = true, replyToMessageId = response.messageId)
1616

src/telebot/private/api.nim

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ proc sendAnimation*(b: TeleBot, chatId: int64, animation: string, duration = 0,
331331
result = getMessage(res)
332332

333333
proc sendPoll*(b: TeleBot, chatId: int64, question: string, options: seq[string], isAnonymous = false, kind = "",
334-
allowsMultipleAnswers = false, correctOptionId = 0, isClosed = false,
334+
allowsMultipleAnswers = false, correctOptionId = 0, explanation = "", explanationParseMode = "",
335+
openPeriod = 0, closeDate = 0, isClosed = false,
335336
disableNotification = false, replyToMessageId = 0, replyMarkup: KeyboardMarkup = nil): Future[Message] {.async.} =
336337
END_POINT("sendPoll")
337338
var data = newMultipartData()
@@ -347,6 +348,14 @@ proc sendPoll*(b: TeleBot, chatId: int64, question: string, options: seq[string]
347348
data["allows_multiple_answers"] = "true"
348349
if correctOptionId != 0:
349350
data["correct_option_id"] = $correctOptionId
351+
if explanation.len != 0:
352+
data["explanation"] = explanation
353+
if explanationParseMode.len != 0:
354+
data["explanation_parse_mode"] = explanationParseMode
355+
if openPeriod != 0:
356+
data["open_period"] = $openPeriod
357+
if closeDate != 0:
358+
data["close_date"] = $closeDate
350359
if isClosed:
351360
data["is_closed"] = "true"
352361
if disableNotification:
@@ -359,11 +368,13 @@ proc sendPoll*(b: TeleBot, chatId: int64, question: string, options: seq[string]
359368
let res = await makeRequest(b, endpoint % b.token, data)
360369
result = getMessage(res)
361370

362-
proc sendDice*(b: TeleBot, chatId: int64, disableNotification = false, replyToMessageId = 0, replyMarkup: KeyboardMarkup = nil): Future[Message] {.async.} =
371+
proc sendDice*(b: TeleBot, chatId: int64, emoji = "", disableNotification = false, replyToMessageId = 0, replyMarkup: KeyboardMarkup = nil): Future[Message] {.async.} =
363372
END_POINT("sendDice")
364373
var data = newMultipartData()
365374

366375
data["chat_id"] = $chatId
376+
if emoji.len != 0:
377+
data["emoji"] = emoji
367378
if disableNotification:
368379
data["disable_notification"] = "true"
369380
if replyToMessageId != 0:
@@ -931,9 +942,6 @@ proc getUpdates*(b: TeleBot, offset, limit = 0, timeout = 50, allowedUpdates: se
931942
b.lastUpdateId = result[result.len - 1]["update_id"].toInt
932943

933944
proc handleUpdate*(b: TeleBot, update: Update) {.async.} =
934-
if update.updateId > b.lastUpdateId:
935-
b.lastUpdateId = update.updateId
936-
937945
# stop process other callbacks if a callback returns true
938946
var stop = false
939947
if update.inlineQuery.isSome:

src/telebot/private/types.nim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import asyncdispatch, options, tables, httpclient
22

3+
4+
converter optionToBool*[T](o: Option[T]): bool = o.isSome()
5+
36
type
47
TelegramObject* = object of RootObj
58

@@ -158,17 +161,23 @@ type
158161
id*: string
159162
question*: string
160163
options*: seq[PollOption]
161-
isClosed*: bool
162164
totalVoterCount*: int
165+
isClosed*: bool
163166
isAnonymous*: bool
167+
kind*: string
164168
allowsMultipleAnswers*: bool
165169
correctOptionId*: int
170+
explanation*: Option[string]
171+
explanationEntities*: Option[seq[MessageEntity]]
172+
openPeriod*: Option[int]
173+
closeDate*: Option[int]
166174

167175
UserProfilePhotos* = object of TelegramObject
168176
totalCount*: int
169177
photos*: seq[seq[PhotoSize]]
170178

171179
Dice* = object of TelegramObject
180+
emoji*: string
172181
value*: int
173182

174183
File* = object of TelegramObject

src/telebot/private/utils.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const
88
API_URL* = "https://api.telegram.org/bot$#/"
99
FILE_URL* = "https://api.telegram.org/file/bot$#/$#"
1010

11-
#macro END_POINT*(s: static[string]) =
12-
# result = parseStmt("const endpoint = \"" & API_URL & s & "\"")
1311
template END_POINT*(`method`: string) =
1412
let endpoint {.used, inject.} = API_URL & `method`
1513

src/telebot/private/webhook.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ proc getWebhookInfo*(b: TeleBot): Future[WebhookInfo] {.async.} =
5252
result = getWebhookInfo(res)
5353

5454

55-
proc startWebhook*(b: Telebot, secret, url: string, port=Port(8080)) =
55+
proc startWebhook*(b: Telebot, secret, url: string, port=Port(8080), clean = false) =
5656
try:
5757
let me = waitFor b.getMe()
5858
b.id = me.id

0 commit comments

Comments
 (0)