telebot.nim

授权协议 MIT License
开发语言 Python
所属分类 应用工具、 IM/聊天/语音工具
软件类型 开源软件
地区 不详
投 递 者 慕容高卓
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

telebot.nim

Async Telegram Bot API Client implement in @Nim-Lang

Notes

From version 1.0.0, procs likes newMessage, newPhoto,.. are gone, use sendMessage, sendDocument instead.If you still prefer the old/ugly way to send stuffs, just import telebot/compat for backward compatible

Installation

$ nimble install telebot

Usage

echo bot

import telebot, asyncdispatch, logging, options
var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
addHandler(L)

const API_KEY = slurp("secret.key")

proc updateHandler(b: Telebot, u: Update): Future[bool] {.async.} =
  if not u.message.isSome:
    # return true will make bot stop process other callbacks
    return true
  var response = u.message.get
  if response.text.isSome:
    let text = response.text.get
    discard await b.sendMessage(response.chat.id, text, parseMode = "markdown", disableNotification = true, replyToMessageId = response.messageId)

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): Future[bool] {.async.} =
  discard await bot.sendPhoto(response.chat.id, "file:///path/to/photo.jpg")

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

For more information please refer to official Telegram Bot API page

相关阅读

相关文章

相关问答

相关文档