Comparing version 1.1.2 to 1.2.0
175
main.js
@@ -36,10 +36,31 @@ 'use strict'; | ||
Api.prototype._setOptions = function (to, from) { | ||
from || (from = {}); | ||
for (var key in from) { | ||
to[key] = from[key]; | ||
} | ||
if (this.keyboard) { | ||
to.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return to; | ||
}; | ||
Api.prototype.hideKeyboard = function (selective) { | ||
this.keyboard = JSON.stringify({ | ||
hide_keyboard: true, | ||
selective: selective || false | ||
}); | ||
return this; | ||
}; | ||
Api.prototype.setKeyboard = function (keyboard, resize, once, selective) { | ||
if (!Array.isArray(keyboard)) { | ||
this.keyboard = { | ||
hide_keyboard: true, | ||
selective: selective || resize || false | ||
}; | ||
return this.hideKeyboard(selective || resize || false); | ||
} else { | ||
this.keyboard = { | ||
this.keyboard = JSON.stringify({ | ||
keyboard: keyboard, | ||
@@ -49,6 +70,5 @@ resize_keyboard: resize || false, | ||
selective: selective || false | ||
}; | ||
}); | ||
} | ||
this.keyboard && (this.keyboard = JSON.stringify(this.keyboard)); | ||
return this; | ||
@@ -80,11 +100,7 @@ }; | ||
Api.prototype.sendMessage = function (chatId, text, options) { | ||
options || (options = {}); | ||
options.chat_id = chatId; | ||
options.text = text; | ||
options = this._setOptions({ | ||
chat_id: chatId, | ||
text: text | ||
}, options); | ||
if (this.keyboard) { | ||
options.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return yarl.post(this.url + 'sendMessage', { body: options, json: true }); | ||
@@ -103,90 +119,98 @@ }; | ||
Api.prototype.sendPhoto = function (chatId, data, options) { | ||
options || (options = {}); | ||
options.chat_id = chatId; | ||
options.photo = fileLoad(data); | ||
options = this._setOptions({ | ||
chat_id: chatId, | ||
photo: fileLoad(data) | ||
}, options); | ||
if (this.keyboard) { | ||
options.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return yarl.post(this.url + 'sendPhoto', { body: options, json: true, multipart: true }); | ||
}; | ||
Api.prototype.sendPhotoFromUrl = function (chatId, url, options) { | ||
return yarl.get(url, { buffer: true }).then(function (res) { | ||
return this.sendPhoto(chatId, res.body, options); | ||
}.bind(this)); | ||
}; | ||
Api.prototype.sendAudio = function (chatId, data, options) { | ||
options || (options = {}); | ||
options.chat_id = chatId; | ||
options.audio = fileLoad(data); | ||
options = this._setOptions({ | ||
chat_id: chatId, | ||
audio: fileLoad(data) | ||
}, options); | ||
if (this.keyboard) { | ||
options.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return yarl.post(this.url + 'sendAudio', { body: options, json: true, multipart: true }); | ||
}; | ||
Api.prototype.sendAudioFromUrl = function (chatId, url, options) { | ||
return yarl.get(url, { buffer: true }).then(function (res) { | ||
return this.sendAudio(chatId, res.body, options); | ||
}.bind(this)); | ||
}; | ||
Api.prototype.sendDocument = function (chatId, data, options) { | ||
options || (options = {}); | ||
options.chat_id = chatId; | ||
options.document = fileLoad(data); | ||
options = this._setOptions({ | ||
chat_id: chatId, | ||
document: fileLoad(data) | ||
}, options); | ||
if (this.keyboard) { | ||
options.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return yarl.post(this.url + 'sendDocument', { body: options, json: true, multipart: true }); | ||
}; | ||
Api.prototype.sendDocumentFromUrl = function (chatId, url, options) { | ||
return yarl.get(url, { buffer: true }).then(function (res) { | ||
return this.sendDocument(chatId, res.body, options); | ||
}.bind(this)); | ||
}; | ||
Api.prototype.sendSticker = function (chatId, data, options) { | ||
options || (options = {}); | ||
options.chat_id = chatId; | ||
options.sticker = fileLoad(data); | ||
options = this._setOptions({ | ||
chat_id: chatId, | ||
sticker: fileLoad(data) | ||
}, options); | ||
if (this.keyboard) { | ||
options.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return yarl.post(this.url + 'sendSticker', { body: options, json: true, multipart: true }); | ||
}; | ||
Api.prototype.sendStickerFromUrl = function (chatId, url, options) { | ||
return yarl.get(url, { buffer: true }).then(function (res) { | ||
return this.sendSticker(chatId, res.body, options); | ||
}.bind(this)); | ||
}; | ||
Api.prototype.sendVideo = function (chatId, data, options) { | ||
options || (options = {}); | ||
options.chat_id = chatId; | ||
options.video = fileLoad(data); | ||
options = this._setOptions({ | ||
chat_id: chatId, | ||
video: fileLoad(data) | ||
}, options); | ||
if (this.keyboard) { | ||
options.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return yarl.post(this.url + 'sendVideo', { body: options, json: true, multipart: true }); | ||
}; | ||
Api.prototype.sendVideoFromUrl = function (chatId, url, options) { | ||
return yarl.get(url, { buffer: true }).then(function (res) { | ||
return this.sendVideo(chatId, res.body, options); | ||
}.bind(this)); | ||
}; | ||
Api.prototype.sendVoice = function (chatId, data, options) { | ||
options || (options = {}); | ||
options.chat_id = chatId; | ||
options.voice = fileLoad(data); | ||
options = this._setOptions({ | ||
chat_id: chatId, | ||
voice: fileLoad(data) | ||
}, options); | ||
if (this.keyboard) { | ||
options.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return yarl.post(this.url + 'sendVoice', { body: options, json: true, multipart: true }); | ||
}; | ||
Api.prototype.sendVoiceFromUrl = function (chatId, url, options) { | ||
return yarl.get(url, { buffer: true }).then(function (res) { | ||
return this.sendVoice(chatId, res.body, options); | ||
}.bind(this)); | ||
}; | ||
Api.prototype.sendLocation = function (chatId, lat, lon, options) { | ||
options || (options = {}); | ||
options.chat_id = chatId; | ||
options.latitude = lat; | ||
options.longitude = lon; | ||
options = this._setOptions({ | ||
chat_id: chatId, | ||
latitude: lat, | ||
longitude: lon | ||
}, options); | ||
if (this.keyboard) { | ||
options.reply_markup = this.keyboard; | ||
delete this.keyboard; | ||
} | ||
return yarl.post(this.url + 'sendLocation', { body: options, json: true }); | ||
@@ -221,5 +245,6 @@ }; | ||
Api.prototype.answerInlineQuery = function (queryId, results, options) { | ||
options || (options = {}); | ||
options.inline_query_id = queryId; | ||
options.results = JSON.stringify(results); | ||
options = this._setOptions({ | ||
inline_query_id: queryId, | ||
results: JSON.stringify(results) | ||
}, options); | ||
@@ -226,0 +251,0 @@ return yarl.post(this.url + 'answerInlineQuery', { body: options, json: true }); |
{ | ||
"name": "tg-yarl", | ||
"author": "Alexey Bystrov <strikeentco@gmail.com>", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "A simple Promise based wrapper over Telegram Bot Api with additional features.", | ||
@@ -20,2 +20,9 @@ "engines": { | ||
"main": "./main.js", | ||
"files": [ | ||
"main.js" | ||
], | ||
"scripts": { | ||
"test": "mocha test", | ||
"test-on-travis": "istanbul cover --report lcovonly ./node_modules/mocha/bin/_mocha" | ||
}, | ||
"repository": { | ||
@@ -31,3 +38,7 @@ "type": "git", | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.4.5", | ||
"should": "^8.2.2" | ||
}, | ||
"license": "MIT" | ||
} |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
201
9173
2
4
2
0