Skip to content

Commit

Permalink
feat: implement message metadata fields
Browse files Browse the repository at this point in the history
This will allow for sending rich ui elements with messages like buttons
or tables.
  • Loading branch information
dwickr committed Jan 12, 2023
1 parent 75acbbd commit 716468d
Show file tree
Hide file tree
Showing 5 changed files with 2,904 additions and 124 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
*.swp
.npmrc
.nyc_output/
32 changes: 26 additions & 6 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,41 @@ class WickrBot extends EventEmitter {
return this.wickr.isConnected(timeout)
}

send(room, content) {
/**
* send is an alias for the sendMessage method
*/
send(room, content, properties) {
// not sure if there's a better way to alias this function
return this.sendMessage(room, content)
return this.sendMessage(room, content, properties)
}

sendToUser(user, content) {
/**
* sendToUser calls the cmdSend1to1Message API to send a message to a user
*
* @param {string, array} user The username or usernames to send the 1:1 message to
* @param {string} content The message body
* @param {object} properties Additional values to send with the message
* @returns void
*/
sendToUser(user, content, properties) {
if (typeof user === 'string') {
user = [user]
}
return this.wickr.cmdSend1to1Message(user, content)
return this.wickr.cmdSend1to1Message(user, content, '', '', '', [], JSON.stringify(properties?.meta)|| '')
}

sendMessage(room, content) {
/**
* sendMessage calls the cmdSendRoomMessage API to send a message to a room
*
* @param {string} room The vgroupid of the room
* @param {string} content The message body
* @param {object} properties Additional values to send with the message
* @returns void
*/
sendMessage(room, content, properties) {
try {
return this.wickr.cmdSendRoomMessage(room, content)
// TODO: I might need to stringify propeties.meta here
return this.wickr.cmdSendRoomMessage(room, content, '', '', '', [], JSON.stringify(properties?.meta) || '')
} catch (error) {
console.error('Error sending message:', error)
}
Expand Down
Loading

0 comments on commit 716468d

Please sign in to comment.