From ccb101560b8553dc6f2d9b3b89776c96b6b3c6b3 Mon Sep 17 00:00:00 2001 From: yago Date: Sun, 15 Feb 2015 14:33:08 +0100 Subject: [PATCH] Functions _send_document and send_document_from_url --- bot/utils.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bot/utils.lua b/bot/utils.lua index 85943be..bfc80f2 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -257,4 +257,24 @@ function rmtmp_cb(cb_extra, success, result) end -- Finaly call the callback cb_function(cb_extra, success, result) +end + +-- Send document to user and delete it when finished. +-- cb_function and cb_extra are optionals callback +function _send_document(receiver, file_path, cb_function, cb_extra) + local cb_extra = { + file_path = file_path, + cb_function = cb_function or ok_cb, + cb_extra = cb_extra or false + } + -- Call to remove with optional callback + send_document(receiver, file_path, rmtmp_cb, cb_extra) +end + +-- Download the image and send to receiver, it will be deleted. +-- cb_function and cb_extra are optionals callback +function send_document_from_url(receiver, url, cb_function, cb_extra) + local file_path = download_to_file(url, false) + print("File path: "..file_path) + _send_document(receiver, file_path, cb_function, cb_extra) end \ No newline at end of file