mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
feat: link previews
After this commit, previews for links will be enabled by default. To disable it, use linkPreview: false as an option when sending the message. close #98
This commit is contained in:
@@ -381,6 +381,7 @@ class Client extends EventEmitter {
|
||||
*/
|
||||
async sendMessage(chatId, content, options = {}) {
|
||||
let internalOptions = {
|
||||
linkPreview: options.linkPreview === false ? undefined : true,
|
||||
caption: options.caption,
|
||||
quotedMessageId: options.quotedMessageId,
|
||||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : []
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
||||
window.Store.Cmd = window.mR.findModule('Cmd')[0].default;
|
||||
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
|
||||
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
|
||||
|
||||
window.Store.Validators = window.mR.findModule('findLinks')[0];
|
||||
};
|
||||
|
||||
exports.LoadUtils = () => {
|
||||
@@ -76,6 +76,17 @@ exports.LoadUtils = () => {
|
||||
delete options.location;
|
||||
}
|
||||
|
||||
if (options.linkPreview) {
|
||||
delete options.linkPreview;
|
||||
const link = window.Store.Validators.findLink(content);
|
||||
if (link) {
|
||||
const preview = await window.Store.Wap.queryLinkPreview(link.url);
|
||||
if (!preview.status) {
|
||||
options = { ...options, ...preview};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const newMsgId = new window.Store.MsgKey({
|
||||
from: window.Store.Conn.me,
|
||||
to: chat.id,
|
||||
|
||||
Reference in New Issue
Block a user