feat: Mention users, get user number from Contact model

This commit is contained in:
Pedro Lopez
2020-02-08 03:19:51 -04:00
parent ef80f966ea
commit 5616613807
5 changed files with 18 additions and 2 deletions

View File

@@ -59,7 +59,7 @@ Take a look at [example.js](https://github.com/pedroslopez/whatsapp-web.js/blob/
| Add group participants | ✅ | | Add group participants | ✅ |
| Kick group participants | ✅ | | Kick group participants | ✅ |
| Promote/demote group participants | ✅ | | Promote/demote group participants | ✅ |
| Mention users | _pending_ | | Mention users | |
| Get contact info | ✅ | | Get contact info | ✅ |
| Get profile pictures | ✅ | | Get profile pictures | ✅ |
| Set user status message | ✅ | | Set user status message | ✅ |

View File

@@ -131,6 +131,12 @@ client.on('message', async msg => {
const newStatus = msg.body.split(' ')[1]; const newStatus = msg.body.split(' ')[1];
await client.setStatus(newStatus); await client.setStatus(newStatus);
msg.reply(`Status was updated to *${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]
});
} }
}); });

View File

@@ -247,7 +247,8 @@ class Client extends EventEmitter {
async sendMessage(chatId, content, options={}) { async sendMessage(chatId, content, options={}) {
let internalOptions = { let internalOptions = {
caption: options.caption, 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) { if(content instanceof MessageMedia) {

View File

@@ -20,6 +20,12 @@ class Contact extends Base {
*/ */
this.id = data.id; this.id = data.id;
/**
* Contact's phone number
* @type {string}
*/
this.number = data.userid;
/** /**
* Indicates if the contact is a business contact * Indicates if the contact is a business contact
* @type {boolean} * @type {boolean}

View File

@@ -40,6 +40,8 @@ exports.LoadUtils = () => {
delete options.quotedMessageId; delete options.quotedMessageId;
} }
options.mentionedJidList = options.mentionedJidList.map(cId=> window.Store.Contact.get(cId).id);
let locationOptions = {}; let locationOptions = {};
if (options.location) { if (options.location) {
locationOptions = { locationOptions = {
@@ -145,6 +147,7 @@ exports.LoadUtils = () => {
res.isGroup = contact.isGroup; res.isGroup = contact.isGroup;
res.isWAContact = contact.isWAContact; res.isWAContact = contact.isWAContact;
res.isMyContact = contact.isMyContact; res.isMyContact = contact.isMyContact;
res.userid = contact.userid;
return res; return res;
}; };