Add very crude ping command (ref #14)

This commit is contained in:
Tulir Asokan
2017-11-30 21:15:32 +02:00
parent 51bc1f30da
commit eaff8204b8
+16
View File
@@ -299,6 +299,22 @@ commands.api = async (sender, args, reply, app) => {
}
}
function timeout(promise, ms = 2500) {
return new Promise((resolve, reject) => {
promise.then(resolve, reject)
setTimeout(() => reject(new Error("API call response not received")), ms)
})
}
commands.ping = async (sender, args, reply) => {
try {
await timeout(sender.telegramPuppet.client("contacts.getContacts", {}))
reply("Connection seems OK.")
} catch (err) {
reply(`Not connected: ${err}`)
}
}
module.exports = {
commands,
run,