cenko.tech

Making a Webex bot say which space it means

The eurl bot's join message said "this space", which means nothing once the text is pasted somewhere else. A four-line change makes it name the space.

eurl is an open-source Webex bot that gives a Webex space a short public join link. Type eurl url in a space and the bot replies with the link and who is allowed to use it.

The symptom#

The reply always looked like this:

Only users in the domain(s) example.com can join this space using https://eurl.io/#1A2B3C-AB

Inside the space, that is fine. But people copy that sentence out of the space and paste it into other chats, wikis and emails, and once it leaves the room, “this space” points at nothing. Issue #12 reported exactly that back in 2023.

The cause#

The message text was a fixed string. The bot already knew the space’s name: sendJoinDetails() receives the whole publicspace record, and its title field is stored and kept in sync through the rooms:updated webhook. It just never used it.

The fix#

Use the title when there is one, and keep the old wording when there is not, so older records without a stored title cannot end up with an empty name in bold:

// fall back to "this space" for older records where title wasn't yet stored
var spaceName = publicspace.title ? "**"+publicspace.title+"**" : "this space";

Both reply variants (open space, and locked space where the bot is not a moderator) now use spaceName instead of the literal text. After the change:

Only users in the domain(s) example.com can join The Greatest Webex Team room ever! using https://eurl.io/#1A2B3C-AB

No schema change and no extra API call: the data was already there.

What I could not test#

The repository has no test suite, and running the bot needs a live MongoDB instance and a real bot token, which I did not have. The pull request says so plainly and asks the maintainers to check it against a real space, including one with a blank title to exercise the fallback. It is still open.

cd ~/blog