Skip to content

Commit 6135f93

Browse files
committed
Bot API 5.4
1 parent 60fbb1d commit 6135f93

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

src/telebot/private/api.nim

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,10 @@ proc copyMessage*(b: TeleBot, chatId, fromChatId: string, messageId: int, captio
524524
result = unmarshal(res, MessageId)
525525

526526

527-
proc sendChatAction*(b: TeleBot, chatId, action: string): Future[void] {.async.} =
527+
proc sendChatAction*(b: TeleBot, chatId: ChatId, action: ChatAction): Future[void] {.async.} =
528528
var data = newMultipartData()
529-
data["chat_id"] = chatId
530-
data["action"] = action
529+
data["chat_id"] = $chatId
530+
data["action"] = toLowerAscii($action)
531531

532532
discard makeRequest(b, procName, data)
533533

@@ -1224,28 +1224,35 @@ proc getGameHighScores*(b: TeleBot, userId: int, chatId = 0, messageId = 0, inli
12241224
let res = await makeRequest(b, procName, data)
12251225
result = unmarshal(res, seq[GameHighScore])
12261226

1227-
1228-
proc createChatInviteLink*(b: Telebot, chatId: ChatId, expireDate = 0, memberLimit = 0): Future[ChatInviteLink] {.async.} =
1227+
proc createChatInviteLink*(b: Telebot, chatId: ChatId, name = "", expireDate = 0, memberLimit = 0, createsJoinRequest = false): Future[ChatInviteLink] {.async.} =
12291228
var data = newMultipartData()
12301229

12311230
data["chat_id"] = $chatId
1231+
if name.len > 0:
1232+
data["name"] = name
12321233
if expireDate > 0:
12331234
data["expire_date"] = $expireDate
12341235
if memberLimit > 0:
12351236
data["member_limit"] = $memberLimit
1237+
if createsJoinRequest:
1238+
data["creates_join_request"] = "true"
12361239

12371240
let res = await makeRequest(b, procName, data)
12381241
result = unmarshal(res, seq[ChatInviteLink])
12391242

1240-
proc editChatInviteLink*(b: Telebot, chatId: ChatId, inviteLink: string, expireDate = 0, memberLimit = 0): Future[ChatInviteLink] {.async.} =
1243+
proc editChatInviteLink*(b: Telebot, chatId: ChatId, inviteLink: string, name = "", expireDate = 0, memberLimit = 0, createsJoinRequest = false): Future[ChatInviteLink] {.async.} =
12411244
var data = newMultipartData()
12421245

12431246
data["chat_id"] = $chatId
12441247
data["invite_link"] = invite_link
1248+
if name.len > 0:
1249+
data["name"] = name
12451250
if expireDate > 0:
12461251
data["expire_date"] = $expireDate
12471252
if memberLimit > 0:
12481253
data["member_limit"] = $memberLimit
1254+
if createsJoinRequest:
1255+
data["creates_join_request"] = "true"
12491256

12501257
let res = await makeRequest(b, procName, data)
12511258
result = unmarshal(res, seq[ChatInviteLink])
@@ -1258,3 +1265,21 @@ proc revokeChatInviteLink*(b: Telebot, chatId: ChatId, inviteLink: string): Futu
12581265

12591266
let res = await makeRequest(b, procName, data)
12601267
result = unmarshal(res, seq[ChatInviteLink])
1268+
1269+
proc approveChatJoinRequest*(b: Telebot, chatId: ChatId, userId: int): Future[bool] {.async.} =
1270+
var data = newMultipartData()
1271+
1272+
data["chat_id"] = $chatId
1273+
data["user_id"] = $user_id
1274+
1275+
let res = await makeRequest(b, procName, data)
1276+
result = unmarshal(res, bool)
1277+
1278+
proc declineChatJoinRequest*(b: Telebot, chatId: ChatId, userId: int): Future[bool] {.async.} =
1279+
var data = newMultipartData()
1280+
1281+
data["chat_id"] = $chatId
1282+
data["user_id"] = $user_id
1283+
1284+
let res = await makeRequest(b, procName, data)
1285+
result = unmarshal(res, bool)

src/telebot/private/types.nim

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ converter optionToBool*[T](o: Option[T]): bool = o.isSome()
77
type
88
TelegramObject* = object of RootObj
99

10+
ChatAction* = enum
11+
TYPING
12+
UPLOAD_PHOTO
13+
RECORD_VIDEO
14+
UPLOAD_VIDEO
15+
RECORD_VOICE
16+
UPLOAD_VOICE
17+
UPLOAD_DOCUMENT
18+
CHOOSE_STICKER
19+
FIND_LOCATION
20+
RECORD_VIDEO_NOTE
21+
UPLOAD_VIDEO_NOTE
22+
1023
ChatId* = int64|string
1124

1225
UpdateCallback* = proc(bot: Telebot, update: Update): Future[bool] {.gcsafe.}
@@ -360,10 +373,13 @@ type
360373
ChatInviteLink* = object of TelegramObject
361374
inviteLink*: string
362375
creator*: User
376+
createsJoinRequest*: bool
363377
isPrimary*: bool
364378
isRevoked*: bool
379+
name*: Option[string]
365380
expireDate*: Option[int]
366381
memberLimit*: Option[int]
382+
pendingJoinRequestCount*: Option[int]
367383

368384
ChatMember* = object of TelegramObject
369385
user*: User
@@ -440,6 +456,13 @@ type
440456
newChatMember*: ChatMember
441457
inviteLink*: Option[ChatInviteLink]
442458

459+
ChatJoinRequest* = object of TelegramObject
460+
chat*: Chat
461+
fomrUser*: User
462+
date*: int
463+
bio*: Option[string]
464+
inviteLink*: Option[ChatInviteLink]
465+
443466
ChatPermissions* = object of TelegramObject
444467
canSendMessages*: Option[bool]
445468
canSendMediaMessages*: Option[bool]
@@ -473,6 +496,7 @@ type
473496
pollAnswer*: Option[PollAnswer]
474497
myChatMember*: Option[ChatMemberUpdated]
475498
chatMember*: Option[ChatMemberUpdated]
499+
chatJoinRequest*: Option[ChatJoinRequest]
476500

477501
#------------------
478502
# Game
@@ -879,25 +903,3 @@ type
879903
COMMAND_SCOPE_CHAT = "chat"
880904
COMMAND_SCOPE_CHAT_ADMINISTARTORS = "chat_administrators"
881905
COMMAND_SCOPE_CHAT_MEMBER = "chat_member"
882-
883-
884-
885-
#[BotCommandScope* = object of TelegramObject
886-
kind*: string
887-
888-
BotCommandScopeDefault* = object of BotCommandScope
889-
890-
#BotCommandScopeAllPrivateChats* = ref object of BotCommandScope
891-
892-
#BotCommandScopeAllGroupChats* = ref object of BotCommandScope
893-
894-
#BotCommandScopeAllChatAdministrators* = ref object of BotCommandScope
895-
896-
BotCommandScopeChat* = object of BotCommandScope
897-
chatId*: int64
898-
899-
#BotCommandScopeChatAdministrator* = ref object of BotCommandScopeChat
900-
901-
BotCommandScopeChatMember* = object of BotCommandScopeChat
902-
userId*: int64
903-
]#

0 commit comments

Comments
 (0)