Open erickythierry opened 4 years ago
Try this:
/**
Try this:
/**
- @Private
- Send Sticker
- @param {*} sticker
- @param {*} chatId '000000000000@c.us'
- @param metadata about the image. Based on sharp metadata */ window.WAPI._sendSticker = async function (sticker, chatId, metadata) { var chat = Store.Chat.get(chatId) let stick = new window.Store.Sticker.modelClass(); stick.x_clientUrl = sticker.clientUrl; stick.__x_filehash = sticker.filehash; stick.x_id = sticker.filehash; stick.x_uploadhash = sticker.uploadhash; stick.__x_mediaKey = sticker.mediaKey; stick.x_initialized = false; stick.__x_mediaData.mediaStage = 'INIT'; stick.mimetype = 'image/webp'; stick.height = (metadata && metadata.height) ? metadata.height : 512; stick.width = (metadata && metadata.width) ? metadata.width : 512; await stick.initialize(); return await stick.sendToChat(chat); };
Thanks for the answer. could you tell me what kind of information do i put in the variable sticker ?, and how could i generate the content of the variable metadata? I don't understand javascript so it is a little difficult for me to understand how to fill the script with the image data that I want to send as a sticker. sorry for my questions. it is because I am already a few days trying to do this function and nothing yet ... thanks again.
Try this: /**
- @Private
- Send Sticker
- @param {*} sticker
- @param {*} chatId '000000000000@c.us'
- @param metadata about the image. Based on sharp metadata */ window.WAPI._sendSticker = async function (sticker, chatId, metadata) { var chat = Store.Chat.get(chatId) let stick = new window.Store.Sticker.modelClass(); stick.x_clientUrl = sticker.clientUrl; stick.__x_filehash = sticker.filehash; stick.x_id = sticker.filehash; stick.x_uploadhash = sticker.uploadhash; stick.__x_mediaKey = sticker.mediaKey; stick.x_initialized = false; stick.__x_mediaData.mediaStage = 'INIT'; stick.mimetype = 'image/webp'; stick.height = (metadata && metadata.height) ? metadata.height : 512; stick.width = (metadata && metadata.width) ? metadata.width : 512; await stick.initialize(); return await stick.sendToChat(chat); };
Thanks for the answer. could you tell me what kind of information do i put in the variable sticker ?, and how could i generate the content of the variable metadata? I don't understand javascript so it is a little difficult for me to understand how to fill the script with the image data that I want to send as a sticker. sorry for my questions. it is because I am already a few days trying to do this function and nothing yet ... thanks again.
by looking at the function, sticker is a json object with following properties clientUrl, filehash, uploadhash, mediaKey
Though I'm not sure what type those properties are
If anyone can use this function, please post an example.
Up
Hello everyone. I've been trying for a few days to find some way to send images as a sticker. I want to create a bot that receives an image and responds with that image as a sticker.
I found a topic here on issue #492 that talks about something like this but I couldn't get it to work in my code. some help?
thanks for listening
I tried to add this code in WAPI.js but I couldn't use it
window.WAPI.sendSticker = function ({sticker, chatid, quotedMsgId}, done) { var idUser = new window.Store.UserConstructor(chatid, { intentionallyUsePrivateConstructor: true }); // create new chat return Store.Chat.find(idUser).then(async (chat) => { //var mediaBlob = window.WAPI.base64ImageToFile(sticker.data, 'file.webp'); // Since Whatsapp Web doesn't really support sending custom stickers, we have to trick it by using one // of the built-in sticker objects and changing some of the properties before we send it. let prIdx = Store.StickerPack.pageWithIndex(0); await Store.StickerPack.fetchAt(0); if (Store.StickerPack._models.length == 0) { console.log('Could not fetch any sticker packs.'); if (done !== undefined) done(false); return; } await Store.StickerPack._pageFetchPromises[prIdx]; await Store.StickerPack._models[0].stickers.fetch(); if (Store.StickerPack._models[0].stickers._models.length == 0) { console.log('Could not fetch any stickers in the first pack.'); if (done !== undefined) done(false); return; } let stick = Store.StickerPack._models[0].stickers._models[0]; stick.__x_clientUrl = sticker.url; stick.__x_filehash = sticker.filehash; stick.__x_uploadhash = sticker.uploadhash; stick.__x_mediaKey = sticker.mediaKey; //stick.__x__mediaObject.filehash = sticker.filehash; //stick.__x__mediaObject.mediaBlob._blob = mediaBlob; //stick.__x__mediaObject.size = mediaBlob.size; await stick.initialize(); stick.sendToChat(chat); if (done !== undefined) done(true); }); }