diff --git a/README.md b/README.md index fea7316..cb402c0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/yagop/node-telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Build status](https://ci.appveyor.com/api/projects/status/ujko6bsum3g5msjh/branch/master?svg=true)](https://ci.appveyor.com/project/yagop/node-telegram-bot-api/branch/master) [![Coverage Status](https://coveralls.io/repos/yagop/node-telegram-bot-api/badge.svg?branch=master)](https://coveralls.io/r/yagop/node-telegram-bot-api?branch=master) [![bitHound Score](https://www.bithound.io/github/yagop/node-telegram-bot-api/badges/score.svg)](https://www.bithound.io/github/yagop/node-telegram-bot-api) [![https://telegram.me/node_telegram_bot_api](https://img.shields.io/badge/Telegram-node__telegram__bot__api-blue.svg)](https://telegram.me/node_telegram_bot_api) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) +[![Build Status](https://travis-ci.org/yagop/node-telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Build status](https://ci.appveyor.com/api/projects/status/ujko6bsum3g5msjh/branch/master?svg=true)](https://ci.appveyor.com/project/yagop/node-telegram-bot-api/branch/master) [![Coverage Status](https://coveralls.io/repos/yagop/node-telegram-bot-api/badge.svg?branch=master)](https://coveralls.io/r/yagop/node-telegram-bot-api?branch=master) [![bitHound Score](https://www.bithound.io/github/yagop/node-telegram-bot-api/badges/score.svg)](https://www.bithound.io/github/yagop/node-telegram-bot-api) [![https://telegram.me/node_telegram_bot_api](https://img.shields.io/badge/💬 Telegram-node__telegram__bot__api-blue.svg)](https://telegram.me/node_telegram_bot_api) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬 Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez) Node.js module to interact with official [Telegram Bot API](https://core.telegram.org/bots/api). A bot token is needed, to obtain one, talk to [@botfather](https://telegram.me/BotFather) and create a new bot. diff --git a/package.json b/package.json index e914159..3563409 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "bluebird": "^2.10.1", "debug": "^2.2.0", "mime": "^1.3.4", + "file-type": "^3.3.1", "request": "^2.64.0" }, "devDependencies": { diff --git a/src/telegram.js b/src/telegram.js index cc29788..d7ed6dd 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -9,6 +9,7 @@ var request = require('request'); var stream = require('stream'); var util = require('util'); var mime = require('mime'); +var fileType = require('file-type'); var path = require('path'); var URL = require('url'); var fs = require('fs'); @@ -236,6 +237,16 @@ TelegramBot.prototype._formatSendData = function (type, data) { contentType: mime.lookup(fileName) } }; + } else if(util.isBuffer(data)){ + var filetype = fileType(data); + formData = {}; + formData[type] = { + value: data, + options: { + filename: 'data.' + filetype.ext, + contentType: filetype.mime + } + }; } else if (fs.existsSync(data)) { fileName = path.basename(data); formData = {};