Skip to content

Async client for Telegram Bot API in pure Nim

License

Notifications You must be signed in to change notification settings

Geksan/telebot.nim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Async client for Telegram Bot API in pure Nim

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Nim 100.0%