Skip to content

Commit

Permalink
whatsapp solution completed
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurboss committed Nov 12, 2023
1 parent 8096fa8 commit c54f2c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
4 changes: 0 additions & 4 deletions apps/server/whatsapp-common/src/firebaseRD.creds.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export const useFireBaseRealTimeDatabaseStoreAuthState = async (

const writeData = async (data: any, file: string) => {
data = JSON.stringify(data, BufferJSON.replacer);
console.log('Writing data type ', typeof data);
console.log('Writing data ', data);
collection.child(processFileName(file)).set(data);
return;
};
Expand All @@ -39,8 +37,6 @@ export const useFireBaseRealTimeDatabaseStoreAuthState = async (
if (typeof finalRead === 'string') {
finalRead = JSON.parse(finalRead, BufferJSON.reviver);
}
console.log('final REad ', finalRead);
console.log(typeof finalRead);
return finalRead;
} catch (error) {
return null;
Expand Down
15 changes: 8 additions & 7 deletions apps/server/whatsapp-common/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function connectToWhatsApp() {
// logger: pin({ level: 'debug' }),
// can provide additional config here
printQRInTerminal: true,
shouldSyncHistoryMessage: () => false,
// shouldSyncHistoryMessage: () => false,
browser: Browsers.ubuntu('Desktop'),
syncFullHistory: false,
});
Expand Down Expand Up @@ -60,17 +60,17 @@ async function connectToWhatsApp() {
if (!ServerConfigBehavior.value.dbReadStarted) {
ReadMessagesFromFirebase();
}
} else {
console.log(connection);
}
});
sock.ev.on('presence.update', (update) => {
console.log(update.id, 'Is Online', update.presences);
});

messageSubject.subscribe((a) => {
if (ServerConfigBehavior.value.whatsappLoggedIn) {
if (typeof a.message.replaceAll === 'function') {
a.message = a.message.replaceAll('@n@', '\n');
a.message = a.message.replaceAll('\\n', '\n');
}
console.log(a.message);
sock.sendMessage(`${a.number}@s.whatsapp.net`, {
footer: 'Confidential',
text: a.message,
});
}
Expand All @@ -86,6 +86,7 @@ setInterval(() => {
});
}, 5000);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function ReadMessagesFromFirebase() {
const ref = firebaseDb.ref(_generalConfig.readPath);
const CB: (a: DataSnapshot, b?: string | null) => void = (a) => {
Expand Down

0 comments on commit c54f2c8

Please sign in to comment.