webex-notify
v1.0.4
Published
A simple library to send Webex notifications (Text, Markdown, Files, Adaptive Cards)
Maintainers
Readme
Webex Notify Lib
A simple and reusable Node.js library for sending notifications to Cisco Webex via a Bot. Supports Text, Markdown, Files, and Adaptive Cards.
Installation
npm install webex-notify
# Or local:
# npm install ./webex-notify-libGetting Started
1. Get a Bot Access Token
- Go to Webex for Developers.
- Click Create a New App and select Bot.
- Fill in the details (Name, Bot Username, Icon).
- Once created, copy the Bot Access Token.
2. Get a Room ID
The easiest way to find a Room ID is to add your bot to a room and have it list the rooms it is in.
const WebexNotify = require('webex-notify');
const bot = new WebexNotify('YOUR_BOT_ACCESS_TOKEN');
// List all rooms the bot is part of
bot.listRooms().then(rooms => {
rooms.forEach(room => {
console.log(`Title: ${room.title} | ID: ${room.id}`);
});
});Usage
const WebexNotify = require('webex-notify');
const token = 'YOUR_BOT_ACCESS_TOKEN';
const roomId = 'YOUR_ROOM_ID';
const bot = new WebexNotify(token);
// 1. Send Text
bot.send(roomId, { text: 'Hello World!' });
// 2. Send Markdown
bot.send(roomId, { markdown: '**Hello** from *WebexNotify*!' });
// 3. Send File
bot.send(roomId, {
text: 'Here is a photo',
files: ['https://example.com/photo.jpg']
});
// 4. Send Adaptive Card
const card = { ... }; // Your Adaptive Card JSON
bot.send(roomId, {
text: 'New Card',
attachments: [card]
});
// 5. List Rooms
const rooms = await bot.listRooms();
// 6. Get Bot Details
const me = await bot.getMe();
console.log(`Bot Name: ${me.displayName}`);
// 7. List Members in a Room
const members = await bot.listMembers(roomId);
// 8. Add Member to Room
await bot.addMember(roomId, '[email protected]');Limitations
Bots in Group Rooms
Webex Bots have visibility restrictions in Group Rooms.
- A Bot cannot List Messages in a Group Room unless it was mentioned in those messages.
- Calls to
listMessages()in a Group Room will typically fail withFailed to get activityor return an empty list. - Consequence: The Bot cannot retrospectively find its own messages to delete them.
Workaround for Deletion: If you need the Bot to delete its messages in a Group Room, you must record the Message ID immediately after sending it.
const msg = await bot.send(roomId, { text: 'Test' });
saveIdToFile(msg.id); // Save this ID locally
// Later, read file and use bot.deleteMessage(id)