Skip to content
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
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