From fa813796e81e9ccc0cf8eedf70c18cba29ac3747 Mon Sep 17 00:00:00 2001 From: Tore Bjolseth Date: Sun, 2 May 2021 20:22:02 +0200 Subject: [PATCH] roomid-bot: add title of space and unencoded id to message as well 1. Title is nice to have if you use the bot often, so you can look in your chat history to find earlier ids 2. Unencoded id can be useful since there has been some changes and confusion around this lately in webex --- examples/roomid-phantom.js | 48 ++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/examples/roomid-phantom.js b/examples/roomid-phantom.js index 2816a8d..67296cc 100644 --- a/examples/roomid-phantom.js +++ b/examples/roomid-phantom.js @@ -28,7 +28,6 @@ bot.interpreter.prefix = ""; const SparkClient = require("node-sparky"); const sparky = new SparkClient({ token: process.env.ACCESS_TOKEN }); - bot.onCommand("about", function (command) { sparky.messageSend({ roomId: command.message.roomId, @@ -74,23 +73,36 @@ bot.onEvent("memberships", "created", function (trigger) { let email = person.emails[0]; debug("found inquirer: " + email); - // Send a direct message - sparky.messageSend({ - toPersonEmail: email, - markdown: "Found roomId: **" + newMembership.roomId + "**\n\nWill now leave the space you asked me to inquire on..." - }) - .then(function (message) { - - // Leave inquired room - sparky.membershipRemove(newMembership.id) - .then(function () { - sparky.messageSend({ - toPersonEmail: email, - markdown: "Job done: I have silently left the space... Let me know when you need other identifiers ;-)" - }); - }) - }); - }) + sparky.roomGet(newMembership.roomId) + .then(function (room) { + const { id, title } = room; + const unencoded = Buffer.from(id, "base64").toString(); + let msg = "Details for the room you just added me to:\n"; + msg += `\n* Name: **${title}**`; + msg += `\n* Room id (encoded): **${id}**`; + msg += `\n* Room id (not encoded): **${unencoded}** \n`; + msg += "\nI will now leave that space."; + + // Send a direct message + sparky.messageSend({ + toPersonEmail: email, + markdown: msg, + }) + .then(function (message) { + + // Leave inquired room + sparky.membershipRemove(newMembership.id) + .then(function () { + sparky.messageSend({ + toPersonEmail: email, + markdown: "Job done: I have silently left the space... Let me know when you need other identifiers ;-)" + }); + }) + }); + }) + }); + + } } });