Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
windkh committed May 13, 2021
1 parent 5f3ba88 commit 92c2859
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

# [9.4.2] - 2021-05-13
### added workaround for editMessageMedia support as sending local files does not work
- workaround for - [#178](https://github.com/windkh/node-red-contrib-telegrambot/issues/178)
- created issue - https://github.com/yagop/node-telegram-bot-api/issues/876

# [9.4.1] - 2021-05-06
### added editMessageMedia support

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-telegrambot",
"version": "9.4.1",
"version": "9.4.2",
"description": "Telegram bot nodes for Node-RED",
"dependencies": {
"bluebird": "^3.5.1",
Expand Down
45 changes: 44 additions & 1 deletion telegrambot/99-telegrambot.js
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,6 @@ module.exports = function (RED) {
// 2 arguments: content, options
case 'editMessageCaption':
case 'editMessageText':
case 'editMessageMedia':
case 'editMessageReplyMarkup':
if (this.hasContent(msg)) {
node.telegramBot[type](msg.payload.content, msg.payload.options)
Expand All @@ -1930,6 +1929,20 @@ module.exports = function (RED) {
});
}
break;

// TODO: https://github.com/windkh/node-red-contrib-telegrambot/issues/178
// https://github.com/yagop/node-telegram-bot-api/issues/876
case 'editMessageMedia':
if (this.hasContent(msg)) {
node.editMessageMedia(msg.payload.content, msg.payload.options)
.catch(function (ex) {
node.processError(ex, msg, nodeSend, nodeDone);
})
.then(function (result) {
node.processResult(result, msg, nodeSend, nodeDone);
});
}
break;

// 2 arguments: chatId , content
case 'setChatTitle':
Expand Down Expand Up @@ -2044,6 +2057,36 @@ module.exports = function (RED) {
} // forward
};

// TODO: https://github.com/windkh/node-red-contrib-telegrambot/issues/178
// TODO: https://github.com/yagop/node-telegram-bot-api/issues/876
this.editMessageMedia = function (media, form = {}){

const opts = {
qs: form,
};
opts.formData = {};

const payload = Object.assign({}, media);
delete payload.media;
delete payload.fileOptions;

try {
const attachName = String(0);
const [formData, fileId] = node.telegramBot._formatSendData(attachName, media.media, media.fileOptions);
if (formData) {
opts.formData[attachName] = formData[attachName];
payload.media = `attach://${attachName}`;
} else {
payload.media = fileId;
}
} catch (ex) {
return Promise.reject(ex);
}

opts.qs.media = JSON.stringify(payload);
return node.telegramBot._request('editMessageMedia', opts);
}

this.on('input', function (msg, nodeSend, nodeDone) {
nodeSend =
nodeSend ||
Expand Down

0 comments on commit 92c2859

Please sign in to comment.