FKLC / WhatsAppToDiscord

WhatsAppToDiscord is a Discord bot that uses WhatsApp Web as a bridge between Discord and WhatsApp.
https://fklc.github.io/WhatsAppToDiscord/
MIT License
247 stars 70 forks source link

bot crashing and token saving #77

Closed SukhOberoi closed 2 years ago

SukhOberoi commented 2 years ago

the bot crashes quite often and whenever i restart the bot it asks for the token everytime and i have to kick the bot and readd it to the server for it to work. should i send the log file here? (im kinda a noob to this stuff btw)

spookycookie27 commented 2 years ago

same, Im still using GO version.

FKLC commented 2 years ago

same, Im still using GO version.

Go version is no longer supported. JS version is stable at the moment. @SukhSinghOberoi are you also using the Go version?

SukhOberoi commented 2 years ago

same, Im still using GO version.

Go version is no longer supported. JS version is stable at the moment. @SukhSinghOberoi are you also using the Go version?

No. I'm on the latest release (windows). Can't send logs rn. On a vacation and don't have access to my server outside local network

FKLC commented 2 years ago

@SukhSinghOberoi okay np. You can upload here, though I suggest checking for possible private info in logs before uploading.

Z0MBlI commented 2 years ago

i have the same problem. i use the lastest version

FKLC commented 2 years ago

Could you send logs?

spookycookie27 commented 2 years ago

from the terminal on macOS

Last login: Thu Jun 23 23:16:44 on ttys002 xxx@StevesMacBook WA2DC JS Version % ./WA2DC-macOS It seems like this is your first run. Please enter your bot token: redacted Invite the bot using the following link: https://discordapp.com/oauth2/authorize?client_id=reddacted&scope=bot&permissions=536879120 Bot is now running. Press CTRL-C to exit. /snapshot/WhatsAppToDiscord/src/whatsapp_manager.js:59 if (!['conversation', 'extendedTextMessage', 'imageMessage', 'videoMessage', 'audioMessage', 'documentMessage', 'stickerMessage'].some(el => Object.keys(message.message).includes(el))) { ^

TypeError: Cannot convert undefined or null to object at Function.keys () at /snapshot/WhatsAppToDiscord/src/whatsapp_manager.js:59:153 at Array.some () at EventEmitter. (/snapshot/WhatsAppToDiscord/src/whatsapp_manager.js:59:135) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

RESTART BOT - back to the beginning again :(

Node.js v18.1.0 xxxx@StevesMacBook WA2DC JS Version % ./WA2DC-macOS It seems like this is your first run. Please enter your bot token: redacted Invite the bot using the following link: https://discordapp.com/oauth2/authorize?client_id=redacted&scope=bot&permissions=536879120

and the logs

{"level":30,"time":1656022951166,"pid":21751,"hostname":"StevesMacBook","msg":"Starting"} {"level":30,"time":1656022951617,"pid":21751,"hostname":"StevesMacBook","msg":"Update checked."} {"level":30,"time":1656022951626,"pid":21751,"hostname":"StevesMacBook","msg":"Initialized database."} {"level":30,"time":1656022987211,"pid":21751,"hostname":"StevesMacBook","msg":"Loaded settings."} {"level":30,"time":1656022987212,"pid":21751,"hostname":"StevesMacBook","msg":"Loaded contacts."} {"level":30,"time":1656022987213,"pid":21751,"hostname":"StevesMacBook","msg":"Loaded chats."} {"level":30,"time":1656022987887,"pid":21751,"hostname":"StevesMacBook","msg":"Discord client started."} {"level":30,"time":1656022988245,"pid":21751,"hostname":"StevesMacBook","msg":"Repaired channels."} {"level":30,"time":1656022988413,"pid":21751,"hostname":"StevesMacBook","msg":"WhatsApp client started."} {"level":30,"time":1656022988851,"pid":21751,"hostname":"StevesMacBook","browser":["Baileys","Chrome","4.0.0"],"helloMsg":{"clientHello":{"ephemeral":"LOgW6t7Xf8i6p/JL24RMuYx076/UeA8dreiuzcXtFWk="}},"msg":"connected to WA Web"} {"level":30,"time":1656022988971,"pid":21751,"hostname":"StevesMacBook","msg":"handshake complete"} {"level":30,"time":1656022988972,"pid":21751,"hostname":"StevesMacBook","node":{"passive":true,"userAgent":{"platform":"WEB","appVersion":{"primary":2,"secondary":2222,"tertiary":11},"mcc":"000","mnc":"000","osVersion":"0.1","manufacturer":"","device":"Desktop","osBuildNumber":"0.1","releaseChannel":"RELEASE","localeLanguageIso6391":"en","localeCountryIso31661Alpha2":"US"},"webInfo":{"webSubPlatform":"WEB_BROWSER"},"connectType":"WIFI_UNKNOWN","connectReason":"USER_ACTIVATED","regData":{"eRegid":"AAAANg==","eKeytype":"BQ==","eIdent":"HQNOAWTcnKVL+TKrNfUCIo3ny7JJxuVbGOJorMfrOzk=","eSkeyId":"AAAB","eSkeyVal":"+hqARhgSoSb3Sm6IYQveSdDvGEp9Uk6E5E+7k16WPTY=","eSkeySig":"TkBRsW4V20JwLSCirefuuFBJYXuPEUyct+mhwGTJrqbqdHYEseAm3NYQ7/3UM7IfetybB93w2nkef68nzp/shA==","buildHash":"iY/3BIuIma3uGZPeXN50dQ==","companionProps":"CgdCYWlsZXlzEgYIBBAAGAAYASAA"}},"msg":"not logged in, attempting registration..."} {"level":30,"time":1656023069245,"pid":21751,"hostname":"StevesMacBook","jid":"redacted:41@s.whatsapp.net","msg":"registered connection, restart server"} {"level":30,"time":1656023069246,"pid":21751,"hostname":"StevesMacBook","error":{"data":null,"isBoom":true,"isServer":false,"output":{"statusCode":410,"payload":{"statusCode":410,"error":"Gone","message":"Restart Required"},"headers":{}}},"msg":"connection closed"} {"level":40,"time":1656023069246,"pid":21751,"hostname":"StevesMacBook","msg":"If your process stalls here, make sure to implement the reconnect logic as shown in https://github.com/adiwajshing/Baileys/blob/master/Example/example.ts#:~:text=reconnect"} {"level":50,"time":1656023069876,"pid":21751,"hostname":"StevesMacBook","err":{"type":"Error","message":"Restart Required","stack":"Error: Restart Required\n at WebSocket. (/snapshot/WhatsAppToDiscord/node_modules/@adiwajshing/baileys/lib/Socket/socket.js:433:17)","data":null,"isBoom":true,"isServer":false,"output":{"statusCode":410,"payload":{"statusCode":410,"error":"Gone","message":"Restart Required"},"headers":{}}},"msg":"Restart Required"} {"level":30,"time":1656023070374,"pid":21751,"hostname":"StevesMacBook","browser":["Baileys","Chrome","4.0.0"],"helloMsg":{"clientHello":{"ephemeral":"/kW+Z6u5OfDP6IpnAqZBucM9LbBosSg7XWZGdJqEaHk="}},"msg":"connected to WA Web"} {"level":30,"time":1656023070495,"pid":21751,"hostname":"StevesMacBook","msg":"handshake complete"} {"level":30,"time":1656023070495,"pid":21751,"hostname":"StevesMacBook","node":{"username":"redacted","passive":true,"userAgent":{"platform":"WEB","appVersion":{"primary":2,"secondary":2222,"tertiary":11},"mcc":"000","mnc":"000","osVersion":"0.1","manufacturer":"","device":"Desktop","osBuildNumber":"0.1","releaseChannel":"RELEASE","localeLanguageIso6391":"en","localeCountryIso31661Alpha2":"US"},"webInfo":{"webSubPlatform":"WEB_BROWSER"},"connectType":"WIFI_UNKNOWN","connectReason":"USER_ACTIVATED","device":41},"msg":"logging in..."} {"level":30,"time":1656023070676,"pid":21751,"hostname":"StevesMacBook","msg":"uploaded pre-keys"} {"level":30,"time":1656023070903,"pid":21751,"hostname":"StevesMacBook","msg":"opened connection to WA"} {"level":40,"time":1656023070904,"pid":21751,"hostname":"StevesMacBook","msg":"no name present, ignoring presence update request..."} {"level":30,"time":1656023070926,"pid":21751,"hostname":"StevesMacBook","msg":"got 0 offline messages/notifications"} {"level":50,"time":1656023084299,"pid":21751,"hostname":"StevesMacBook","msgId":"3EB066C6D839006F7F7C","params":["No sender key for: redacted@g.us::redacted:38::0"],"msg":"failure in decrypting message"} {"level":30,"time":1656023084310,"pid":21751,"hostname":"StevesMacBook","name":"Steve","msg":"received pushName"} {"level":30,"time":1656023112033,"pid":21987,"hostname":"StevesMacBook","msg":"Starting"} {"level":30,"time":1656023112440,"pid":21987,"hostname":"StevesMacBook","msg":"Update checked."} {"level":30,"time":1656023112446,"pid":21987,"hostname":"StevesMacBook","msg":"Initialized database."}

spookycookie27 commented 2 years ago

so I deleted all apps in Discord Developers, and all bots. Created a new App, new Bot token, and deleted all previous channels in Discord created by GO version. Ran into AUTH immediate problems as you can see trying to validate the token. No messages in discord, no new channels created after scanning the QR code in WA.

This was by running the WADC-macOS build with no previous database.

I previously managed to get this all working a few weeks back, but it was throwing so many errors and crashing frequently so I went back to the GO version which works flawlessly everytime. I also attached the debugger in VSCode and found exceptions thrown after I had got it working, here is one minor fix (as an example) which I committed to my own branch, but I dont have permissions to submit a PR. in discord_manager.js line 59 quotedMessage can be null, not sure why..

    if (message.contextInfo.isForwarded) {
        content += `> Forwarded Message:\n${message.text}`;
    }
    else if (message.contextInfo.quotedMessage) {
        content += `> ${quotedName}: ${message.contextInfo.quotedMessage.conversation.split('\n').join('\n> ')}\n${message.text}`;
    }
    break;
spookycookie27 commented 2 years ago

OK I have got it running again on JS version, and Ill post errors/logs

spookycookie27 commented 2 years ago

Excellent, thanks for applying my fix. I will post more exceptions as they arise.

For anyone having problems trying to authorise the bot follow this guide.

  1. Delete all the previously created WA channels from Discord including Controlroom.
  2. Delete the old bot & token by deleting the Application in Discord Developers
  3. Create a new App and Bot token in Discord Devlopers portal (store the token in a text file for ref or leave the web page open)
  4. In WA, delete any previously saved linked-devices
  5. Start with an empty folder, place the app file in there.
  6. If running macOS or Linux version give permissions to the file chmod +x WA2DC-linux . On Mac you should right click and open the file. This applies permissions to run the file (from non-trusted developer) and close again.
  7. Run the executable ./WA2DC-linux from a terminal. If running PC I think its simple double click on .exe,
  8. Authorise the token, follow its instructions in terminal
  9. Look for the QR code in the control room and scan it with WhatsApp in settings / devices
FKLC commented 2 years ago

@Z0MBlI I checked your logs but unfortunately v0.6.7 doesn't log errors before exit. I pushed a new version and it catches errors before exit. So please run with that version and report back here. I deleted the original comment you made because it included your phone number.

Z0MBlI commented 2 years ago

thx would it be possible for the bot to save the data so that it can find its way back to where it was after a restart? i run it on my pc

FKLC commented 2 years ago

This is normally the case, but when the bot crashes it can't save, and since the bot fails on the first run, it can't save your token info etc. causing you to enter it everytime. If it works for a moment, then run the bot enter your token invite it and then hit control + c to initiate saving the state of the bot before exit.

Z0MBlI commented 2 years ago

oh nice thx for help it works

Z0MBlI commented 2 years ago

log.txt can you fix the errors?

I have the problem when I restart the bot that all the messages are deleted in the discord and whatsapp groups don't work properly either

FKLC commented 2 years ago

@Z0MBlI now the bot saves the state no matter the exit reason. it shouldn't reset everything now.