-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
149 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,35 @@ | ||
# This Bot receives any Document file, responds on chat with file metadata and file contents. | ||
import telebot, asyncdispatch, options, strformat, httpclient, json | ||
|
||
const API_KEY = "" # Add your API Key here. | ||
const API_KEY = slurp("secret.key") | ||
|
||
|
||
proc handleUpdate(bot: TeleBot): UpdateCallback = | ||
proc updateHandler(bot: TeleBot, e: Update) {.async.} = | ||
let | ||
url_getfile = fmt"https://api.telegram.org/bot{API_KEY}/getFile?file_id=" | ||
api_file = fmt"https://api.telegram.org/file/bot{API_KEY}/" | ||
|
||
proc cb(e: Update) {.async.} = | ||
var response = e.message.get | ||
if response.document.isSome: | ||
let | ||
document = response.document.get | ||
file_name = document.file_name.get | ||
mime_type = document.mime_type.get | ||
file_id = document.file_id | ||
file_size = document.file_size.get | ||
responz = await newAsyncHttpClient().get(url_getfile & file_id) # file_id > file_path | ||
responz_body = await responz.body | ||
file_path = parseJson(responz_body)["result"]["file_path"].getStr() | ||
responx = await newAsyncHttpClient().get(api_file & file_path) # file_path > file | ||
file_content = await responx.body | ||
msg0_text = fmt"file_name: {file_name}, mime_type: {mime_type}, file_id: {file_id}, file_size: {file_size}, file_path: {file_path}" | ||
var | ||
message0 = newMessage(response.chat.id, msg0_text) # metadata | ||
message1 = newMessage(response.chat.id, file_content) # file contents | ||
discard await bot.send(message0) | ||
discard await bot.send(message1) | ||
result = cb | ||
var response = e.message.get | ||
if response.document.isSome: | ||
let | ||
document = response.document.get | ||
file_name = document.file_name.get | ||
mime_type = document.mime_type.get | ||
file_id = document.file_id | ||
file_size = document.file_size.get | ||
responz = await newAsyncHttpClient().get(url_getfile & file_id) # file_id > file_path | ||
responz_body = await responz.body | ||
file_path = parseJson(responz_body)["result"]["file_path"].getStr() | ||
responx = await newAsyncHttpClient().get(api_file & file_path) # file_path > file | ||
file_content = await responx.body | ||
msg0_text = fmt"file_name: {file_name}, mime_type: {mime_type}, file_id: {file_id}, file_size: {file_size}, file_path: {file_path}" | ||
var | ||
message0 = newMessage(response.chat.id, msg0_text) # metadata | ||
message1 = newMessage(response.chat.id, file_content) # file contents | ||
discard await bot.send(message0) | ||
discard await bot.send(message1) | ||
|
||
let | ||
bot = newTeleBot(API_KEY) | ||
handler = handleUpdate(bot) | ||
bot.onUpdate(handler) | ||
let bot = newTeleBot(API_KEY) | ||
|
||
bot.onUpdate(updateHandler) | ||
bot.poll(666) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
# This Bot Sends itself as Document file, responds on chat with source file to download. | ||
import telebot, asyncdispatch, options, os | ||
|
||
const API_KEY = "" # Add your API Key here. | ||
const API_KEY = slurp("secret.key") | ||
|
||
|
||
proc handleUpdate(bot: TeleBot): UpdateCallback = | ||
proc updateHandler(bot: TeleBot, e: Update) {.async.} = | ||
let this_file = "file://" & getCurrentDir() & "/file_send_bot.nim" | ||
proc cb(e: Update) {.async.} = | ||
var document = newDocument(e.message.get.chat.id, this_file) | ||
document.caption = this_file | ||
discard await bot.send(document) | ||
result = cb | ||
|
||
var document = newDocument(e.message.get.chat.id, this_file) | ||
document.caption = this_file | ||
discard await bot.send(document) | ||
|
||
let bot = newTeleBot(API_KEY) | ||
bot.onUpdate(handleUpdate(bot)) | ||
bot.onUpdate(updateHandler) | ||
bot.poll(666) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import telebot, asyncdispatch, options | ||
|
||
const API_KEY = "" # Add your API Key here. | ||
const API_KEY = slurp("secret.key") | ||
|
||
proc geoHandler(bot: TeleBot): CommandCallback = | ||
proc cb(e: Command) {.async.} = | ||
let message = newLocation(e.message.chat.id, longitude=42.0, latitude=42.0) | ||
discard await bot.send(message) | ||
result = cb | ||
proc geoHandler(bot: TeleBot, e: Command) {.async.} = | ||
let message = newLocation(e.message.chat.id, longitude=42.0, latitude=42.0) | ||
discard await bot.send(message) | ||
|
||
let bot = newTeleBot(API_KEY) | ||
bot.onCommand("geo", geoHandler(bot)) # Use /geo on Telegram chat to trigger. | ||
bot.onCommand("geo", geoHandler) # Use /geo on Telegram chat to trigger. | ||
bot.poll(666) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
import telebot, asyncdispatch, options, logging, os | ||
|
||
|
||
const API_KEY = "" # Add your API Key here. | ||
const API_KEY = slurp("secret.key") | ||
|
||
|
||
addHandler(newConsoleLogger(fmtStr="$levelname, [$time] ")) | ||
|
||
proc handleUpdate(bot: TeleBot): UpdateCallback = | ||
proc cb(e: Update) {.async.} = | ||
let message = newPhoto(e.message.get.chat.id, "file://" & getCurrentDir() & "/sample.jpg") | ||
discard await bot.send(message) | ||
result = cb | ||
proc updateHandler(bot: TeleBot, e: Update) {.async.} = | ||
let message = newPhoto(e.message.get.chat.id, "file://" & getCurrentDir() & "/sample.jpg") | ||
discard await bot.send(message) | ||
|
||
let | ||
bot = newTeleBot(API_KEY) | ||
handler = handleUpdate(bot) | ||
let bot = newTeleBot(API_KEY) | ||
|
||
bot.onUpdate(handler) | ||
bot.onUpdate(updateHandler) | ||
bot.poll(500) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
version = "0.4.0" | ||
version = "0.4.1" | ||
author = "Huy Doan" | ||
description = "Async Telegram Bot API Client" | ||
license = "MIT" | ||
skipDirs = @["examples"] | ||
|
||
requires "nim >= 0.17.0" | ||
requires "asyncevents >= 0.3.0" |
Oops, something went wrong.