Open aarctb opened 1 year ago
@yisbug can you help me to make this functions works please?
// change whatsapp presenct to available or available // send chat composing | paused async sendPresenceUpdate(type , toJid = null) { let node; if(type === 'available' || type === 'unavailable') { node = new ProtocolTreeNode('presence',{ name: 'Jolly Martin', type: type, }); } else { node = new ProtocolTreeNode('chatstate', { from: this.mobile+"@s.whatsapp.net", to: toJid+"@s.whatsapp.net", type: type, // composing | paused }, [ new ProtocolTreeNode(type, {})] ); } this.sendNode(node); } // change profile status async updateProfileStatus(status) { const node = new ProtocolTreeNode('iq', { to: "@s.whatsapp.net", type: 'set', xmlns: 'status', id: 'long' }, [new ProtocolTreeNode('status', {}, null, [Buffer.from(status, 'utf-8')])] ); this.sendNode(node); }
Sorry, your code is a bit messy. Next, what's wrong with this code? Please describe it in detail.
@yisbug I want to change the profile status and send chat composing and chat pauded before to send a message to a contact..
I added the bellow functions in whatsapp.js file to try it and both not working, I would like to know if you can help me to do it works because you have more knowlogde in your own lib.
This coding is based on Bailes
async sendPresenceUpdate(type , toJid = null) {
let node;
if(type === 'available' || type === 'unavailable') {
node = new ProtocolTreeNode('presence',{
name: 'Jolly Martin',
type: type,
});
} else {
node = new ProtocolTreeNode('chatstate',
{
from: this.mobile+"@s.whatsapp.net",
to: toJid+"@s.whatsapp.net",
type: type, // composing | paused
}, [ new ProtocolTreeNode(type, {})]
);
}
this.sendNode(node);
}
// change profile status
async updateProfileStatus(status) {
const node = new ProtocolTreeNode('iq',
{
to: "@s.whatsapp.net",
type: 'set',
xmlns: 'status',
id: 'long'
},
[new ProtocolTreeNode('status', {}, null, [Buffer.from(status, 'utf-8')])]
);
this.sendNode(node);
}
@yisbug I want to change the profile status and send chat composing and chat pauded before to send a message to a contact..
I added the bellow functions in whatsapp.js file to try it and both not working, I would like to know if you can help me to do it works because you have more knowlogde in your own lib.
This coding is based on Bailes
async sendPresenceUpdate(type , toJid = null) { let node; if(type === 'available' || type === 'unavailable') { node = new ProtocolTreeNode('presence',{ name: 'Jolly Martin', type: type, }); } else { node = new ProtocolTreeNode('chatstate', { from: this.mobile+"@s.whatsapp.net", to: toJid+"@s.whatsapp.net", type: type, // composing | paused }, [ new ProtocolTreeNode(type, {})] ); } this.sendNode(node); } // change profile status async updateProfileStatus(status) { const node = new ProtocolTreeNode('iq', { to: "@s.whatsapp.net", type: 'set', xmlns: 'status', id: 'long' }, [new ProtocolTreeNode('status', {}, null, [Buffer.from(status, 'utf-8')])] ); this.sendNode(node); }
set chatstate:
ChatStateProtocolEntity.js
const ProtocolEntity = require('../ProtocolEntity');
const ProtocolTreeNode = require('../ProtocolTreeNode');
class ChatStateProtocolEntity extends ProtocolEntity {
constructor(state = 'composing', to) {
super('chatstate');
this.state = state;
this.to = to;
}
toProtocolTreeNode() {
const attribs = {
to: this.to,
};
const node = this._createProtocolTreeNode(attribs, null, null);
node.addChild(new ProtocolTreeNode(this.state));
return node;
}
}
module.exports = ChatStateProtocolEntity;
and
async setChatState(state, jid) {
return await this.sendEntity(new ChatStateProtocolEntity(state, utils.normalize(jid)));
}
SetStatusIqProtocolEntity.js
const IqProtocolEntity = require('../Iq/IqProtocolEntity');
const ProtocolTreeNode = require('../ProtocolTreeNode');
const constants = require('../../config/constants');
class SetStatusIqProtocolEntity extends IqProtocolEntity {
constructor(text = null, _id = null) {
super('status', _id, 'set', constants.WHATSAPP_SERVER);
this.setData(text);
}
setData(text) {
this.text = text;
}
toProtocolTreeNode() {
const node = super.toProtocolTreeNode();
const statusNode = new ProtocolTreeNode('status', {}, [], this.text);
node.addChild(statusNode);
return node;
}
}
module.exports = SetStatusIqProtocolEntity;
These codes are from another commercial paid version of my project. If you are interested, you can contact me by email.
@yisbug can you help me to make this functions works please?