-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Feat/sticker #479
Feat/sticker #479
Conversation
src/util/Injected.js
Outdated
return await window.WWebJS.sendSticker(stickerInfo, chatId); | ||
}; | ||
|
||
window.WWebJS.sendSticker = async function (stickerInfo, chatId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename this to sendStickerRaw, as there still is potential to add a sendSticker via Sticker Packs which is not yet included in this PR.
// Keep in mind: This is merely a suggestion and maybe @pedroslopez will accept as is.
Also I found some functions that could help retrieve Information on already added Stickers if you want to add that as well: Retrieve StickerPacks from phone: Store.StickerPack.sync() Check if StickerPacks are fetched from phone: Store.StickerPack.hasFetchedData() Retrieve Stickers from StickerPack: Store.StickerPack.models[0].stickers.fetch() Sticker Info: Store.StickerPack.models[0].stickers.models[0] Reset StickerPacks Store.StickerPack.reset() Reset Stickers from StickerPack: Store.StickerPack.models[0].stickers.reset() |
Cool, I'd really apreciate if you can add that
Also, after using it for a while, I think Another thing is that I think |
I'm currently short on time. So I doubt I will be able to implement it soon enough on my own. Concerning the internal conversion: I see the added value of converting images internally, however I believe it should only be done if it's via WhatsApp. I assume, that WhatsApp has their own conversion tool integrated somewhere within their code. Or at least hope so. |
Thanks for contributing! I haven't yet had the chance to look over this properly, but just seeing it very quickly I see stickers are sent using a new function Again, I haven't yet looked into the implementation, so let me know your thoughts. |
@aliyss, |
@pedroslopez, Let me know if even then you want me to join this on What about internal conversion so that it could handle formats other than |
@mpirescarvalho Thank you so much for implementing the send sticker function 😄 👍 |
Yeah, However, if we're sending messages using the regular |
Ok, so a lots of things have changed here. Sending StickerFirst, initial functions Usage example: const webpBase64Data = 'UklGRlxWAABXRUJQVlA4WAoAAAAQAAAAgAMAFgIAQUxQSFQ0AAAB...';
client.on('message', async msg => {
if (msg.body.startsWith('dp!sticker')) {
const stickerMedia = new MessageMedia('image/webp', webpBase64Data );
client.sendMessage(msg.from, stickerMedia, { sendMediaAsSticker: true });
}
}); Media formatMedia format constraint also doesn't exists anymore (images are converted internally), so it's now possible to send any image format like jpeg to the function. You can do: const stickerMedia = MessageMedia.fromFilePath('imagem.jpg');
client.sendMessage(msg.from, stickerMedia, { sendMediaAsSticker: true }); VideosYou can also send any videos format as stickers (though I only tested it with mp4). You should keep in mind that whatsapp stickers max size is 1MB, so anything bigger than that will not be sent, resulting in a error. Important: const client = new Client({
...
ffmpegPath: 'path/to/ffmpeg'
}); |
This comment has been minimized.
This comment has been minimized.
Disregard my previous message, the issue I mentioned seems to be unrelated and happens even without sending any stickers with the library. Could more data be missing from the message? I know stickers have some information like sticker name and pack name, but I don't see those being set anywhere. |
Yes they have aditional information but those seems to be optional. I'm using this branch on my bot (it allows users to send images and the bot creates a sticker from it) from a week and I haven't had any problems at all. I think we need anyone else to test it, maybe I'm missing something too. |
@mpirescarvalho @pedroslopez @mpirescarvalho again, thanks for implementing the sticker function, it will be so much useful for me, and many others! |
Alright, the issue I was having was due to the I just need to test out the animated sticker portion, which I'll get to most likely tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Adds the option `sendMediaAsSticker` that will take care of converting media to appropriate formats and send it as a sticker. Note that ffmpeg is required to properly convert animated stickers that are not in webp format. Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
* 'master' of https://github.com/pedroslopez/whatsapp-web.js: chore: mark version v1.12.0 docs: switch links to point to the guide docs: fix error generating Label docs feat: Get message delivery information (close pedroslopez#418) feat: mark chat as unread (pedroslopez#475) feat: add GroupChat types (pedroslopez#485) docs: fix typo feat: added starred indicator to messages (pedroslopez#501) feat: star/unstar messages (pedroslopez#494) feat: get Contact's "About" text (close pedroslopez#491) feat: get links included in message (pedroslopez#457) feat: send media as stickers (pedroslopez#479) docs: fix slight typo feat: send media as document (pedroslopez#490) feat: Get registered ID for a given phone number (pedroslopez#483) feat(interface): Open chat search, open chat at message position (pedroslopez#447) feat: WA Business Labels support (pedroslopez#407) # Conflicts: # package.json
Adds the option `sendMediaAsSticker` that will take care of converting media to appropriate formats and send it as a sticker. Note that ffmpeg is required to properly convert animated stickers that are not in webp format. Co-authored-by: Pedro S. Lopez <pedroslopez@me.com>
First, good job with the project!
This PR adds the possibility to send
WEBP
images as stickers.That's how you would send stickers:
It's also possible to send using
chat
objects:You could also load the image from file just like normal images:
IMAGES HAS TO BE IN
WEBP
FORMAT FOR THE STICKERS TO BE SENT PROPERLYThat's the result: