Telegram Shell. Remote access over Telegram bot API.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

38 lines
803 B

const { EOL } = require('os');
const { path } = require('../util/index.js');
const success = (response, mode) => ctx => {
const respondAs = (mode && mode.toLowerCase() === 'html') ? 'replyWithHTML' : 'reply';
return response ? ctx[respondAs](response) : null;
};
const convertCtx = ctx => {
const message = path(['update', 'message'], ctx);
const { id, first_name, username, language_code } = path(['from'], message);
const { text } = message;
return JSON.stringify({
id,
first_name,
username,
language_code,
text,
}, null, 2);
};
const fail = response => ctx => {
if(!response
|| !path(['update', 'message'], ctx)
) return;
console.log(
EOL,
response,
EOL,
`With context: `,
convertCtx(ctx),
);
return ctx.reply(response);
};
module.exports = {
success, fail,
};