Skip to content

Commit

Permalink
telebot: add username field to bot
Browse files Browse the repository at this point in the history
  • Loading branch information
yfzhe committed Jan 27, 2024
1 parent 42c39f7 commit c4a53a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions telebot/main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
((webhook-url string? "url"))
-> true?)

(define (bot-init! bot)
(define me (bot-get-me bot))
(set-bot-username! bot (ref (me : user) .username #f)))

(define (bot-start/poll bot handle-update)
(bot-init! bot)
(let loop ([offset 0] [updates '()])
(cond
[(null? updates)
Expand All @@ -34,6 +39,7 @@
(loop (add1 (ref (update : update) .id)) (cdr updates))])))

(define (bot-start/webhook bot handle-update webhook-base port)
(bot-init! bot)
(bot-set-webhook bot
#:webhook-url (string-append webhook-base "/webhook"))

Expand Down
5 changes: 3 additions & 2 deletions telebot/private/bot.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"error.rkt")

(provide bot? make-bot
set-bot-username!
bot-post)

(struct bot (token))
(struct bot (token [username #:mutable]))

(define (make-bot token)
(bot token))
(bot token #f))

(define *tg-api-base* "https://api.telegram.org/bot")

Expand Down

0 comments on commit c4a53a2

Please sign in to comment.