Skip to content

Commit

Permalink
feat: Mention users, get user number from Contact model
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroslopez committed Feb 8, 2020
1 parent ef80f96 commit 5616613
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Take a look at [example.js](https://github.com/pedroslopez/whatsapp-web.js/blob/
| Add group participants ||
| Kick group participants ||
| Promote/demote group participants ||
| Mention users | _pending_ |
| Mention users | |
| Get contact info ||
| Get profile pictures ||
| Set user status message ||
Expand Down
6 changes: 6 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ client.on('message', async msg => {
const newStatus = msg.body.split(' ')[1];
await client.setStatus(newStatus);
msg.reply(`Status was updated to *${newStatus}*`);
} else if (msg.body == '!mention') {
const contact = await msg.getContact();
const chat = await msg.getChat();
chat.sendMessage(`Hi @${contact.number}!`, {
mentions: [contact]
});
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ class Client extends EventEmitter {
async sendMessage(chatId, content, options={}) {
let internalOptions = {
caption: options.caption,
quotedMessageId: options.quotedMessageId
quotedMessageId: options.quotedMessageId,
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : []
};

if(content instanceof MessageMedia) {
Expand Down
6 changes: 6 additions & 0 deletions src/structures/Contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class Contact extends Base {
*/
this.id = data.id;

/**
* Contact's phone number
* @type {string}
*/
this.number = data.userid;

/**
* Indicates if the contact is a business contact
* @type {boolean}
Expand Down
3 changes: 3 additions & 0 deletions src/util/Injected.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ exports.LoadUtils = () => {
delete options.quotedMessageId;
}

options.mentionedJidList = options.mentionedJidList.map(cId=> window.Store.Contact.get(cId).id);

let locationOptions = {};
if (options.location) {
locationOptions = {
Expand Down Expand Up @@ -145,6 +147,7 @@ exports.LoadUtils = () => {
res.isGroup = contact.isGroup;
res.isWAContact = contact.isWAContact;
res.isMyContact = contact.isMyContact;
res.userid = contact.userid;

return res;
};
Expand Down

0 comments on commit 5616613

Please sign in to comment.