Skip to content

Instantly share code, notes, and snippets.

@deanshub
Created January 4, 2019 14:50
Show Gist options
  • Save deanshub/f0ca8a1aa30f63c530e60245b7d32edf to your computer and use it in GitHub Desktop.
Save deanshub/f0ca8a1aa30f63c530e60245b7d32edf to your computer and use it in GitHub Desktop.
import broadlinkController from "../broadlinkController";
import botCommander from "../botCommander";
export default async function(msg) {
const id = msg.from.id;
const name = msg.from.first_name;
const devices = await broadlinkController.getDevices();
const inline_keyboard = [
Object.keys(devices).map(devName => {
return {
text:
devName.charAt(0).toUpperCase() +
devName.slice(1).toLocaleLowerCase(),
callback_data: devName
};
})
];
const keyboardOpts = {
reply_markup: JSON.stringify({
inline_keyboard,
resize_keyboard: true,
one_time_keyboard: true
}),
parse_mode: "Markdown",
disable_web_page_preview: true
};
if (msg.message && msg.message.message_id) {
await botCommander.editMessageText(`Hi ${name}, what do you want to do?`, {
chat_id: msg.message.chat.id,
message_id: msg.message.message_id
});
return botCommander.editMessageReplyMarkup(
{
inline_keyboard
},
{
chat_id: msg.message.chat.id,
message_id: msg.message.message_id
}
);
}
return botCommander.sendMessage(
id,
`Hi ${name}, what do you want to do?`,
keyboardOpts
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment