Skip to content

Commit 6ead699

Browse files
committed
Bot API 4.7
1 parent 38a45f0 commit 6ead699

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

telebot.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "0.7.1"
1+
version = "0.7.2"
22
author = "Huy Doan"
33
description = "Async Telegram Bot API Client"
44
license = "MIT"

telebot/api.nim

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ magic Poll:
156156
replyToMessageId: int {.optional.}
157157
replyMarkup: KeyboardMarkup {.optional.}
158158

159+
magic Dice:
160+
chatId: int64
161+
disableNotification: string {.optional.}
162+
replyToMessageId: int {.optional.}
163+
replyMarkup: KeyboardMarkup {.optional.}
164+
159165
proc getMe*(b: TeleBot): Future[User] {.async.} =
160166
## Returns basic information about the bot in form of a ``User`` object.
161167
END_POINT("getMe")
@@ -376,13 +382,18 @@ proc uploadStickerFile*(b: TeleBot, userId: int, pngSticker: string): Future[typ
376382
let res = await makeRequest(b, endpoint % b.token, data)
377383
result = unmarshal(res, types.File)
378384

379-
proc createNewStickerSet*(b: TeleBot, userId: int, name: string, title: string, pngSticker: string, emojis: string, containsMasks = false, maskPosition: Option[MaskPosition]): Future[bool] {.async.} =
385+
proc createNewStickerSet*(b: TeleBot, userId: int, name: string, title: string, pngSticker: string, tgsSticker: string, emojis: string, containsMasks = false, maskPosition: Option[MaskPosition]): Future[bool] {.async.} =
380386
END_POINT("createNewStickerSet")
381387
var data = newMultipartData()
382388
data["user_id"] = $userId
383389
data["name"] = name
384390
data["title"] = title
385-
data.addFiles({"png_sticker": pngSticker})
391+
if pngSticker.len != 0:
392+
data.addFiles({"png_sticker": pngSticker})
393+
elif tgsSticker.len != 0:
394+
data.addFiles({"tgs_sticker": tgsSticker})
395+
else:
396+
raise newException(ValueError, "Either png_sticker or tgs_sticker must be set")
386397
data["emojis"] = emojis
387398
if containsMasks:
388399
data["contains_masks"] = "true"
@@ -393,12 +404,17 @@ proc createNewStickerSet*(b: TeleBot, userId: int, name: string, title: string,
393404
let res = await makeRequest(b, endpoint % b.token, data)
394405
result = res.toBool
395406

396-
proc addStickerToSet*(b: TeleBot, userId: int, name: string, pngSticker: string, emojis: string, maskPosition: Option[MaskPosition]): Future[bool] {.async.} =
407+
proc addStickerToSet*(b: TeleBot, userId: int, name: string, pngSticker: string, tgsSticker: string, emojis: string, maskPosition: Option[MaskPosition]): Future[bool] {.async.} =
397408
END_POINT("addStickerToSet")
398409
var data = newMultipartData()
399410
data["user_id"] = $userId
400411
data["name"] = name
401-
data.addFiles({"png_sticker": pngSticker})
412+
if pngSticker.len != 0:
413+
data.addFiles({"png_sticker": pngSticker})
414+
elif tgsSticker.len != 0:
415+
data.addFiles({"tgs_sticker": tgsSticker})
416+
else:
417+
raise newException(ValueError, "Either png_sticker or tgs_sticker must be set")
402418
data["emojis"] = emojis
403419
if maskPosition.isSome():
404420
var tmp = ""
@@ -422,6 +438,17 @@ proc deleteStickerFromSet*(b: TeleBot, sticker: string): Future[bool] {.async.}
422438
let res = await makeRequest(b, endpoint % b.token, data)
423439
result = res.toBool
424440

441+
proc setStickerSetThumb*(b: TeleBot, name: string, userId: int, thumb = ""): Future[bool] {.async.} =
442+
END_POINT("setStickerSetThumb")
443+
var data = newMultipartData()
444+
data["name"] = name
445+
data["user_id"] = $userId
446+
if thumb.len != 0:
447+
data.addFiles({"thumb": thumb})
448+
449+
let res = await makeRequest(b, endpoint % b.token, data)
450+
result = res.toBool
451+
425452
proc setChatStickerSet*(b: TeleBot, chatId: string, stickerSetname: string): Future[bool] {.async.} =
426453
END_POINT("setChatStickerSet")
427454
var data = newMultipartData()
@@ -616,6 +643,22 @@ proc answerCallbackQuery*(b: TeleBot, callbackQueryId: string, text = "", showAl
616643
let res = await makeRequest(b, endpoint % b.token, data)
617644
result = res.toBool
618645

646+
proc setMyCommands*(b: TeleBot, commands: seq[BotCommand]): Future[bool] {.async.} =
647+
END_POINT("setMyCommands")
648+
var data = newMultipartData()
649+
var json = ""
650+
marshal(commands, json)
651+
data["commands"] = json
652+
653+
let res = await makeRequest(b, endpoint % b.token, data)
654+
result = res.toBool
655+
656+
proc getMyCommands*(b: TeleBot): Future[seq[BotCommand]] {.async.} =
657+
END_POINT("etMyCommands")
658+
659+
let res = await makeRequest(b, endpoint % b.token)
660+
result = unmarshal(res, seq[BotCommand])
661+
619662
proc answerInlineQuery*[T](b: TeleBot, id: string, results: seq[T], cacheTime = 0, isPersonal = false, nextOffset = "", switchPmText = "", switchPmParameter = ""): Future[bool] {.async.} =
620663
const endpoint = API_URL & "answerInlineQuery"
621664
if results.len == 0:

telebot/types.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type
9898
isAnimated*: bool
9999
containsMasks*: bool
100100
stickers*: seq[Sticker]
101+
thumb*: Option[PhotoSize]
101102

102103
MaskPosition* = object of TelegramObject
103104
point*: string
@@ -171,6 +172,9 @@ type
171172
totalCount*: int
172173
photos*: seq[seq[PhotoSize]]
173174

175+
Dice* = object of TelegramObject
176+
value*: int
177+
174178
File* = object of TelegramObject
175179
fileId*: string
176180
fileUniqueId*: string
@@ -273,6 +277,7 @@ type
273277
location*: Option[Location]
274278
venue*: Option[Venue]
275279
poll*: Option[Poll]
280+
dice*: Option[Dice]
276281
newChatMembers*: Option[seq[User]]
277282
newChatMember*: Option[User]
278283
leftChatMember*: Option[User]
@@ -324,6 +329,10 @@ type
324329
canInviteUsers*: Option[bool]
325330
canPinMessages*: Option[bool]
326331

332+
BotCommand* = object of TelegramObject
333+
command*: string
334+
description*: string
335+
327336
ResponseParameters* = object of TelegramObject
328337
migrateToChatId*: Option[int64]
329338
retryAfter*: Option[int]

0 commit comments

Comments
 (0)