diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0d8af7a..e249f00 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
Added:
+1. Add Bot API v3.4 methods:
+ * (#439) *TelegramBot#editMessageLiveLocation*, *TelegramBot#stopMessageLiveLocation* (by @kamikazechaser)
1. Add `metadata` argument in `message` event (and
friends e.g. `text`, `audio`, etc.) (#409) (by @jlsjonas, @GochoMugo)
1. Add support for Node.js v9 (by @GochoMugo)
diff --git a/doc/api.md b/doc/api.md
index 52cb1a2..9a6bd81 100644
--- a/doc/api.md
+++ b/doc/api.md
@@ -55,6 +55,8 @@ TelegramBot
* [.editMessageReplyMarkup(replyMarkup, [options])](#TelegramBot+editMessageReplyMarkup) ⇒ Promise
* [.getUserProfilePhotos(userId, [options])](#TelegramBot+getUserProfilePhotos) ⇒ Promise
* [.sendLocation(chatId, latitude, longitude, [options])](#TelegramBot+sendLocation) ⇒ Promise
+ * [.editMessageLiveLocation(latitude, longitude, [options])](#TelegramBot+editMessageLiveLocation) ⇒ Promise
+ * [.stopMessageLiveLocation([options])](#TelegramBot+stopMessageLiveLocation) ⇒ Promise
* [.sendVenue(chatId, latitude, longitude, title, address, [options])](#TelegramBot+sendVenue) ⇒ Promise
* [.sendContact(chatId, phoneNumber, firstName, [options])](#TelegramBot+sendContact) ⇒ Promise
* [.getFile(fileId)](#TelegramBot+getFile) ⇒ Promise
@@ -702,6 +704,40 @@ Use this method to send point on the map.
| longitude | Float
| Longitude of location |
| [options] | Object
| Additional Telegram query options |
+
+
+### telegramBot.editMessageLiveLocation(latitude, longitude, [options]) ⇒ Promise
+Use this method to edit live location messages sent by
+the bot or via the bot (for inline bots).
+
+Note that you must provide one of chat_id, message_id, or
+inline_message_id in your request.
+
+**Kind**: instance method of [TelegramBot](#TelegramBot)
+**See**: https://core.telegram.org/bots/api#editmessagelivelocation
+
+| Param | Type | Description |
+| --- | --- | --- |
+| latitude | Float
| Latitude of location |
+| longitude | Float
| Longitude of location |
+| [options] | Object
| Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) |
+
+
+
+### telegramBot.stopMessageLiveLocation([options]) ⇒ Promise
+Use this method to stop updating a live location message sent by
+the bot or via the bot (for inline bots) before live_period expires.
+
+Note that you must provide one of chat_id, message_id, or
+inline_message_id in your request.
+
+**Kind**: instance method of [TelegramBot](#TelegramBot)
+**See**: https://core.telegram.org/bots/api#stopmessagelivelocation
+
+| Param | Type | Description |
+| --- | --- | --- |
+| [options] | Object
| Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) |
+
### telegramBot.sendVenue(chatId, latitude, longitude, title, address, [options]) ⇒ Promise
diff --git a/src/telegram.js b/src/telegram.js
index 98c3323..d518233 100644
--- a/src/telegram.js
+++ b/src/telegram.js
@@ -1185,6 +1185,40 @@ class TelegramBot extends EventEmitter {
return this._request('sendLocation', { form });
}
+ /**
+ * Use this method to edit live location messages sent by
+ * the bot or via the bot (for inline bots).
+ *
+ * Note that you must provide one of chat_id, message_id, or
+ * inline_message_id in your request.
+ *
+ * @param {Float} latitude Latitude of location
+ * @param {Float} longitude Longitude of location
+ * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
+ * @return {Promise}
+ * @see https://core.telegram.org/bots/api#editmessagelivelocation
+ */
+ editMessageLiveLocation(latitude, longitude, form = {}) {
+ form.latitude = latitude;
+ form.longitude = longitude;
+ return this._request('editMessageLiveLocation', { form });
+ }
+
+ /**
+ * Use this method to stop updating a live location message sent by
+ * the bot or via the bot (for inline bots) before live_period expires.
+ *
+ * Note that you must provide one of chat_id, message_id, or
+ * inline_message_id in your request.
+ *
+ * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
+ * @return {Promise}
+ * @see https://core.telegram.org/bots/api#stopmessagelivelocation
+ */
+ stopMessageLiveLocation(form = {}) {
+ return this._request('stopMessageLiveLocation', { form });
+ }
+
/**
* Send venue.
* Use this method to send information about a venue.
diff --git a/test/telegram.js b/test/telegram.js
index 54d1c8f..b300ab2 100644
--- a/test/telegram.js
+++ b/test/telegram.js
@@ -39,6 +39,8 @@ const staticUrl = `http://127.0.0.1:${staticPort}`;
const key = `${__dirname}/../examples/key.pem`;
const ip = '216.58.210.174'; // Google IP ¯\_(ツ)_/¯
const cert = `${__dirname}/../examples/crt.pem`;
+const lat = 47.5351072;
+const long = -52.7508537;
let FILE_ID;
let GAME_CHAT_ID;
let GAME_MSG_ID;
@@ -1042,8 +1044,6 @@ describe('TelegramBot', function telegramSuite() {
utils.handleRatelimit(bot, 'sendLocation', this);
});
it('should send a location', function test() {
- const lat = 47.5351072;
- const long = -52.7508537;
return bot.sendLocation(USERID, lat, long).then(resp => {
assert.ok(is.object(resp));
assert.ok(is.object(resp.location));
@@ -1053,13 +1053,51 @@ describe('TelegramBot', function telegramSuite() {
});
});
+ describe('#editMessageLiveLocation', function editMessageLiveLocationSuite() {
+ let message;
+ before(function before() {
+ utils.handleRatelimit(bot, 'editMessageLiveLocation', this);
+ const opts = { live_period: 86400 };
+ return bot.sendLocation(USERID, lat, long, opts).then(resp => { message = resp; });
+ });
+ it('edits live location', function test() {
+ const opts = { chat_id: USERID, message_id: message.message_id };
+ return bot.editMessageLiveLocation(lat + 1, long + 1, opts).then(resp => {
+ assert.ok(is.object(resp));
+ assert.ok(is.object(resp.location));
+ assert.ok(is.number(resp.location.latitude));
+ assert.ok(is.number(resp.location.longitude));
+ });
+ });
+ });
+
+ describe('#stopMessageLiveLocation', function editMessageLiveLocationSuite() {
+ let message;
+ before(function before() {
+ utils.handleRatelimit(bot, 'stopMessageLiveLocation', this);
+ return bot.sendLocation(USERID, lat, long, { live_period: 86400 })
+ .then((resp) => {
+ message = resp;
+ const opts = { chat_id: USERID, message_id: message.message_id };
+ return bot.editMessageLiveLocation(lat + 1, long + 1, opts);
+ });
+ });
+ it('stops location updates', function test() {
+ const opts = { chat_id: USERID, message_id: message.message_id };
+ return bot.stopMessageLiveLocation(opts).then(resp => {
+ assert.ok(is.object(resp));
+ assert.ok(is.object(resp.location));
+ assert.ok(is.number(resp.location.latitude));
+ assert.ok(is.number(resp.location.longitude));
+ });
+ });
+ });
+
describe('#sendVenue', function sendVenueSuite() {
before(function before() {
utils.handleRatelimit(bot, 'sendVenue', this);
});
it('should send a venue', function test() {
- const lat = 47.5351072;
- const long = -52.7508537;
const title = 'The Village Shopping Centre';
const address = '430 Topsail Rd,St. John\'s, NL A1E 4N1, Canada';
return bot.sendVenue(USERID, lat, long, title, address).then(resp => {