11# telebot.nim
22Async Telegram Bot API Client implement in @Nim-Lang
33
4+ Notes
5+ =====
6+ From version 1.0.0, procs likes ` newMessage ` , ` newPhoto ` ,.. are gone, use ` sendMessage ` , ` sendDocument ` instead.
7+ If you still prefer the old/ugly way to send stuffs, just import ` telebot/compat ` for backward compatible
8+
49Installation
510============
611```
@@ -13,23 +18,23 @@ Usage
1318## echo bot
1419``` nim
1520import telebot, asyncdispatch, logging, options
21+ var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
22+ addHandler(L)
1623
1724const API_KEY = slurp("secret.key")
1825
1926proc updateHandler(b: Telebot, u: Update) {.async.} =
27+ if not u.message.isSome:
28+ return
2029 var response = u.message.get
2130 if response.text.isSome:
22- let
23- text = response.text.get
24- var message = newMessage(response.chat.id, text)
25- message.disableNotification = true
26- message.replyToMessageId = response.messageId
27- message.parseMode = "markdown"
28- discard await b.send(message)
31+ let text = response.text.get
32+ discard await b.sendMessage(response.chat.id, text, parseMode = "markdown", disableNotification = true, replyToMessageId = response.messageId)
2933
3034let bot = newTeleBot(API_KEY)
3135bot.onUpdate(updateHandler)
3236bot.poll(timeout=300)
37+
3338```
3439
3540## send local photo
@@ -39,15 +44,9 @@ import telebot, asyncdispatch, options, logging
3944const API_KEY = slurp("secret.key")
4045
4146proc updateHandler(bot: TeleBot, update: Update): UpdateCallback =
42- var response = update.message.get
43- if response.text.isSome:
44- let
45- text = response.text.get
46- var message = newPhoto(response.chat.id, "file:///path/to/photo.jpg")
47- discard await bot.send(message)
47+ discard await bot.sendPhoto(response.chat.id, "file:///path/to/photo.jpg")
4848
49- let
50- bot = newTeleBot(API_KEY)
49+ let bot = newTeleBot(API_KEY)
5150bot.onUpdate(updateHandler)
5251bot.poll(timeout=300)
5352```
0 commit comments