Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending message not working with new contacts #3045

Closed
1 task done
mohammedsab opened this issue May 20, 2024 · 1 comment
Closed
1 task done

Sending message not working with new contacts #3045

mohammedsab opened this issue May 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mohammedsab
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We Injected your package in our APP using DOTNET framework

When sending message for the first time to new contact. the message does not send

Expected behavior

`window.WWebJS.sendMessage = async (chat, content, options = {}) => {
let attOptions = {};
if (options.attachment) {
attOptions = options.sendMediaAsSticker
? await window.WWebJS.processStickerData(options.attachment)
: await window.WWebJS.processMediaData(options.attachment, {
forceVoice: options.sendAudioAsVoice,
forceDocument: options.sendMediaAsDocument,
forceGif: options.sendVideoAsGif
});

    // added this line
    attOptions.caption = options.caption;
    content = options.sendMediaAsSticker ? undefined : attOptions.preview;
    // added this line
    attOptions.isViewOnce = options.isViewOnce;

    delete options.attachment;
    delete options.sendMediaAsSticker;
}
let quotedMsgOptions = {};
if (options.quotedMessageId) {
    let quotedMessage = window.Store.Msg.get(options.quotedMessageId);

    // TODO remove .canReply() once all clients are updated to >= v2.2241.6
    const canReply = window.Store.ReplyUtils ?
        window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe()) :
        quotedMessage.canReply();

    if (canReply) {
        quotedMsgOptions = quotedMessage.msgContextInfo(chat);
    }
    delete options.quotedMessageId;
}

if (options.mentionedJidList) {
    options.mentionedJidList = await Promise.all(
        options.mentionedJidList.map(async (id) => {
            const wid = window.Store.WidFactory.createWid(id);
            if (await window.Store.QueryExist(wid)) {
                return wid;
            }
        })
    );
    options.mentionedJidList = options.mentionedJidList.filter(Boolean);
}

let locationOptions = {};
if (options.location) {
    locationOptions = {
        type: 'location',
        loc: options.location.description,
        lat: options.location.latitude,
        lng: options.location.longitude
    };
    delete options.location;
}

let vcardOptions = {};
if (options.contactCard) {
    let contact = window.Store.Contact.get(options.contactCard);
    vcardOptions = {
        body: window.Store.VCard.vcardFromContactModel(contact).vcard,
        type: 'vcard',
        vcardFormattedName: contact.formattedName
    };
    delete options.contactCard;
} else if (options.contactCardList) {
    let contacts = options.contactCardList.map(c => window.Store.Contact.get(c));
    let vcards = contacts.map(c => window.Store.VCard.vcardFromContactModel(c));
    vcardOptions = {
        type: 'multi_vcard',
        vcardList: vcards,
        body: undefined
    };
    delete options.contactCardList;
} else if (options.parseVCards && typeof (content) === 'string' && content.startsWith('BEGIN:VCARD')) {
    delete options.parseVCards;
    try {
        const parsed = window.Store.VCard.parseVcard(content);
        if (parsed) {
            vcardOptions = {
                type: 'vcard',
                vcardFormattedName: window.Store.VCard.vcardGetNameFromParsed(parsed)
            };
        }
    } catch (_) {
        // not a vcard
    }
}

if (options.linkPreview) {
    delete options.linkPreview;

    // Not supported yet by WhatsApp Web on MD
    if (!window.Store.MDBackend) {
        const link = window.Store.Validators.findLink(content);
        if (link) {
            const preview = await window.Store.Wap.queryLinkPreview(link.url);
            preview.preview = true;
            preview.subtype = 'url';
            options = { ...options, ...preview };
        }
    }
}

let buttonOptions = {};
if (options.buttons) {
    let caption;
    if (options.buttons.type === 'chat') {
        content = options.buttons.body;
        caption = content;
    } else {
        caption = options.caption ? options.caption : ' '; //Caption can't be empty
    }
    buttonOptions = {
        productHeaderImageRejected: false,
        isFromTemplate: false,
        isDynamicReplyButtonsMsg: true,
        title: options.buttons.title ? options.buttons.title : undefined,
        footer: options.buttons.footer ? options.buttons.footer : undefined,
        dynamicReplyButtons: options.buttons.buttons,
        replyButtons: options.buttons.buttons,
        caption: caption
    };
    delete options.buttons;
}

let listOptions = {};
if (options.list) {
    if (window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi') {
        throw '[LT01] Whatsapp business can\'t send this yet';
    }
    listOptions = {
        type: 'list',
        footer: options.list.footer,
        list: {
            ...options.list,
            listType: 1
        },
        body: options.list.description
    };
    delete options.list;
    delete listOptions.list.footer;
}

const meUser = window.Store.User.getMaybeMeUser();
const isMD = window.Store.MDBackend;
const newId = await window.Store.MsgKey.newId();

const newMsgId = new window.Store.MsgKey({
    from: meUser,
    to: chat.id,
    id: newId,
    participant: isMD && chat.id.isGroup() ? meUser : undefined,
    selfDir: 'out',
});

const extraOptions = options.extraOptions || {};
delete options.extraOptions;

const ephemeralFields = window.Store.EphemeralFields.getEphemeralFields(chat);

const message = {
    ...options,
    id: newMsgId,
    ack: 0,
    body: content,
    from: meUser,
    to: chat.id,
    local: true,
    self: 'out',
    t: parseInt(new Date().getTime() / 1000),
    isNewMsg: true,
    type: 'chat',
    ...ephemeralFields,
    ...locationOptions,
    ...attOptions,
    ...(attOptions.toJSON ? attOptions.toJSON() : {}),
    ...quotedMsgOptions,
    ...vcardOptions,
    ...buttonOptions,
    ...listOptions,
    ...extraOptions
};

await window.Store.SendMessage.addAndSendMsgToChat(chat, message);
return window.Store.Msg.get(newMsgId._serialized);

};`

Steps to Reproduce the Bug or Issue

  1. We use chromedriver for opening whatsapp
  2. Then injected files in whatsapp
  3. Use our system for make events on whatsapp

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Windows
Phone: Andriod

Additional context

No response

@mohammedsab mohammedsab added the bug Something isn't working label May 20, 2024
@alechkos
Copy link
Collaborator

You should check in your code if the injection was done properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants