From e47fbc622eec2028e0ef3773fbb3b50ec0aabbb1 Mon Sep 17 00:00:00 2001 From: Ilias Ismanalijev Date: Thu, 9 Jul 2015 13:31:23 +0200 Subject: [PATCH 1/3] sendlocation --- src/telegram.js | 19 +++++++++++++++++++ test/index.js | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/telegram.js b/src/telegram.js index cf9f0ba..2aab978 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -376,4 +376,23 @@ TelegramBot.prototype.sendChatAction = function (chatId, action) { return this._request('sendChatAction', {qs: query}); }; +/** + * Send location. + * Use this method to send point on the map. + * + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {Float} latitude Latitude of location + * @param {Float} longitude Longitude of location + * @return {Promise} + * @see https://core.telegram.org/bots/api#sendlocation + */ +TelegramBot.prototype.sendLocation = function (chatId, latitude, longitude) { + var query = { + chat_id: chatId, + latitude: latitude, + longitude: longitude + }; + return this._request('sendLocation', {qs: query}); +}; + module.exports = TelegramBot; diff --git a/test/index.js b/test/index.js index 13326b7..73d079c 100644 --- a/test/index.js +++ b/test/index.js @@ -322,4 +322,19 @@ describe('Telegram', function () { }); }); + describe('#sendLocation', function () { + it('should send a location', function (done) { + var bot = new Telegram(TOKEN); + var lat = 47.5351072; + var long = -52.7508537; + bot.sendLocation(USERID, lat, long).then(function (resp) { + resp.should.be.an.instanceOf(Object); + resp.location.should.be.an.instanceOf(Object); + resp.location.latitude.should.be.an.instanceOf(Number); + resp.location.longitude.should.be.an.instanceOf(Number); + done(); + }); + }); + }); + }); From e976b521288036457af1a445e3e2c9530b6c2bff Mon Sep 17 00:00:00 2001 From: Ilias Ismanalijev Date: Thu, 9 Jul 2015 13:36:53 +0200 Subject: [PATCH 2/3] sendlocation with options --- src/telegram.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/telegram.js b/src/telegram.js index 2aab978..c1872b6 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -383,15 +383,15 @@ TelegramBot.prototype.sendChatAction = function (chatId, action) { * @param {Number|String} chatId Unique identifier for the message recipient * @param {Float} latitude Latitude of location * @param {Float} longitude Longitude of location + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#sendlocation */ -TelegramBot.prototype.sendLocation = function (chatId, latitude, longitude) { - var query = { - chat_id: chatId, - latitude: latitude, - longitude: longitude - }; +TelegramBot.prototype.sendLocation = function (chatId, latitude, longitude, options) { + var query = options || {}; + query.chat_id = chatId; + query.latitude = latitude; + query.longitude = longitude; return this._request('sendLocation', {qs: query}); }; From 9ac992c61d116faec58bac3e0e07b0e8f3bbee31 Mon Sep 17 00:00:00 2001 From: Ilias Ismanalijev Date: Thu, 9 Jul 2015 13:40:11 +0200 Subject: [PATCH 3/3] readme for sendlocation --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 2a0fb08..d0ffaa1 100644 --- a/README.md +++ b/README.md @@ -208,4 +208,21 @@ See: https://core.telegram.org/bots/api#sendchataction * **Promise** +## sendLocation(chatId, latitude, longitude, [options]) + +Use this method to send point on the map. + +See: https://core.telegram.org/bots/api#sendlocation + +### Params: + +* **Number|String** *chatId* Unique identifier for the message recipient +* **Float** *latitude* Latitude of location +* **Float** *longitude* Longitude of location +* **Object** *[options]* Additional Telegram query options + +### Return: + +* **Promise** +