-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 and receiving photos? #3
Comments
Hi, I am looking for this feature too and my research result is that WBOT module has this function in api (sendImage method) but for this we need inject/include modules: UserConstructor, MediaCollection. My question, @pedroslopez how can we include other models like Message module? |
@pedroslopez Could something like this help? https://gist.github.com/phpRajat/a6422922efae32914f4dbd1082f3f412 |
Receiving photos is now possible as of v0.3 (https://github.com/pedroslopez/whatsapp-web.js/releases/tag/v0.3.0) I'll leave this issue open until sending is also implemented :) |
window.WAPI.sendImage = function (imgBase64, chatid, filename, caption, done) {
//var idUser = new window.Store.UserConstructor(chatid);
var idUser = new window.Store.UserConstructor(chatid, { intentionallyUsePrivateConstructor: true });
// create new chat
return Store.Chat.find(idUser).then((chat) => {
var mediaBlob = window.WAPI.base64ImageToFile(imgBase64, filename);
var mc = new Store.MediaCollection();
mc.processFiles([mediaBlob], chat, 1).then(() => {
var media = mc.models[0];
media.sendToChat(chat, { caption: caption });
if (done !== undefined) done(true);
});
});
} Stole it from here: https://github.com/mukulhase/WebWhatsapp-Wrapper/blob/master/webwhatsapi/js/wapi.js Edit: Will look into it asap. |
@aliyss I was actually working in this yesterday using a similar solution, and I got it working for any attachment type (except videos for whatever reason), however the ‘.sendToChat’ part doesn’t allow us to get the sent message ID. I basically left off reimplementing the sendToChat function myself combining it with our custom sendMessage function that assigns the ID manually. This seemed to work fine but I need to do some additional testing and clean things up. |
Alright. In that case I'll leave my hands out of it. 😇 |
add await when needed and polish work with files
add await when needed and polish work with files
…/patch Update WhatsApp Web Version (2.2238.7)
It's possibile to send and receive photos? You can give an example?
Thanks for the great work!
The text was updated successfully, but these errors were encountered: