Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roomid-bot: add title of space and unencoded id to message as well #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
tbjolset committed May 2, 2021
commit fa813796e81e9ccc0cf8eedf70c18cba29ac3747
48 changes: 30 additions & 18 deletions examples/roomid-phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ;-)"
});
})
});
})
});


}
}
});
Expand Down