Skip to content

Instantly share code, notes, and snippets.

@saade
Last active October 25, 2017 14:23
Show Gist options
  • Select an option

  • Save saade/a081a4620a22c86ba0f4b106bb3c1a29 to your computer and use it in GitHub Desktop.

Select an option

Save saade/a081a4620a22c86ba0f4b106bb3c1a29 to your computer and use it in GitHub Desktop.
var X_sacs = ["5521999395050",
"555199595050",
"557199595050",
"558182595050",
"5511999595050",
"554192905050",
"554891905050",
"556199595050",
"553199595050",
"5511943613092",
"5511987368864",
"553484006419",
"5511945622248",
"558588690143",
"5511945683025"];
X_makeTest = function(){
X_sacs.forEach( (sac, i) => {
setTimeout( () => {
X_sendMessage(sac, "teste");
setTimeout( () => {
Store.Wap.resyncMessages([ sac + "@c.us" ]);
}, 1500);
}, 500 * i);
});
}
X_checkTest = function(){
X_sacs.forEach( (sac) => {
var chat_i = Store.Chat.models.findIndex( chat => chat.id == sac + "@c.us" );
var last_message = Store.Chat.models[ chat_i ].msgs.models.slice(-1)[0];
if( last_message.body == "teste" ){
console.error( "SAC '" + Store.Chat.models[ chat_i ].formattedTitle + "' não está respondendo, teste enviado às: [" + x_SendDate(last_message.t) + "]");
}else{
console.warn( "SAC '" + Store.Chat.models[ chat_i ].formattedTitle + "' está ok, Respondeu ás: [" + x_SendDate(last_message.t) + "]");
}
});
}
x_SendDate = function( unix ){
var d = new Date( unix * 1000 );
return d.getHours() + ":" + d.getMinutes();
}
X_sendMessage = function(to = null, body = null) {
if (to == null || body == null) return {
'status': 401,
'status_msg': "Invalid user or body text"
}
var id = X_makeID();
var msg = Store.Msg.models[0];
msg.id.id = id;
msg.id.remote = to + "@c.us";
msg.type = "chat";
msg.body = body;
msg.to = to + "@c.us";
msg.t = Math.ceil(new Date().getTime() / 1000);
Store.Msg.send(msg);
}
X_makeID = function() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 20; i++) text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment