Skip to content

Latest commit

 

History

History
54 lines (44 loc) · 1.25 KB

README.md

File metadata and controls

54 lines (44 loc) · 1.25 KB

telebot.nim

Async Telegram Bot API Client implement in @Nim-Lang

Installation

$ nimble install telebot

Usage

echo bot

import telebot, asyncdispatch, logging, options

const API_KEY = slurp("secret.key")

proc updateHandler(b: Telebot, u: Update) {.async.} =
  var response = u.message.get
  if response.text.isSome:
    let
      text = response.text.get
    var message = newMessage(response.chat.id, text)
    message.disableNotification = true
    message.replyToMessageId = response.messageId
    message.parseMode = "markdown"
    discard await b.send(message)

let bot = newTeleBot(API_KEY)
bot.onUpdate(updateHandler)
bot.poll(timeout=300)

send local photo

import telebot, asyncdispatch, options, logging

const API_KEY = slurp("secret.key")

proc updateHandler(bot: TeleBot, update: Update): UpdateCallback =
  var response = update.message.get
  if response.text.isSome:
    let
      text = response.text.get
    var message = newPhoto(response.chat.id, "file:///path/to/photo.jpg")
    discard await bot.send(message)

let
  bot = newTeleBot(API_KEY)
bot.onUpdate(updateHandler)
bot.poll(timeout=300)

For more information please refer to official Telegram Bot API page