Skip to content
Async client for Telegram Bot API in pure Nim
Branch: master
Clone or download
ba0f3 Merge pull request #32 from zestyr/fix-clean
Fix cleanUpdates skipping first message
Latest commit f324b55 May 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples using sam for json encoder/decoder May 13, 2019
telebot Set cleanUpdates timeout to 0 May 16, 2019
.gitignore add echo_bot example Jun 22, 2017
LICENSE Initial commit Jul 2, 2015
README.md Add limit and offset options to bot.poll Oct 16, 2018
nim.cfg first release Jul 2, 2015
telebot.nim Restore async concurrency May 15, 2019
telebot.nimble Restore async concurrency May 15, 2019

README.md

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

You can’t perform that action at this time.