{"id":15068918,"url":"https://github.com/louuke/whatsjava","last_synced_at":"2025-04-10T17:11:25.980Z","repository":{"id":116502082,"uuid":"285685409","full_name":"Louuke/WhatsJava","owner":"Louuke","description":"Implementation of the WhatsApp Web API in Java","archived":false,"fork":false,"pushed_at":"2021-11-08T13:15:00.000Z","size":13353,"stargazers_count":38,"open_issues_count":9,"forks_count":15,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-24T14:51:21.509Z","etag":null,"topics":["java","java11","reverse-engineering","whatsapp","whatsapp-api","whatsapp-web","whatsapp-web-api","whatsappweb"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Louuke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-08-06T22:40:29.000Z","updated_at":"2024-11-28T06:36:22.000Z","dependencies_parsed_at":"2023-11-07T16:01:03.874Z","dependency_job_id":null,"html_url":"https://github.com/Louuke/WhatsJava","commit_stats":null,"previous_names":["louuke/whatsjava","jicunull/whatsjava"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Louuke%2FWhatsJava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Louuke%2FWhatsJava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Louuke%2FWhatsJava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Louuke%2FWhatsJava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Louuke","download_url":"https://codeload.github.com/Louuke/WhatsJava/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248261610,"owners_count":21074223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","java11","reverse-engineering","whatsapp","whatsapp-api","whatsapp-web","whatsapp-web-api","whatsappweb"],"created_at":"2024-09-25T01:39:43.241Z","updated_at":"2025-04-10T17:11:25.950Z","avatar_url":"https://github.com/Louuke.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ! Note !\nThis project is broken and I will most likely no longer maintain it.\nI suggest to switch to the project [WhatsappWeb4j](https://github.com/Auties00/WhatsappWeb4j).\n\n# WhatsJava\nWhatsJava is a reimplementation of the WhatsApp Web API and provides a direct interface for developers.\n\nBig thanks to [@Sigalor](https://github.com/sigalor) and all participants of the [whatsapp-web-reveng project](https://github.com/sigalor/whatsapp-web-reveng) and [@adiwajshing](https://github.com/adiwajshing/Baileys) for the Typescript/Javascript implementation.\n\n### Gradle\n```java\nallprojects {\n    repositories {\n\t...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n```java\ndependencies {\n    implementation 'com.github.JicuNull:WhatsJava:v1.0.2'\n}\n```\nFind more options here: **[Jitpack](https://jitpack.io/#JicuNull/WhatsJava)**\n\n## How to use it\n**Note**: The project is tested with Java 11\n\n## Connect and login\n`WAClient` connects to the WhatsApp backend server and is used for all interactions with the server. Therefore, a new `WAClient` instance needs to be created first.\n\n```java\nWAClient client = new WAClient();\n```\nThe session is opened by calling `openConnection()`.\n```java\nWAClient client = new WAClient();\nclient.openConnection();\n```\nYou can also define a path to a storage location to store keys needed to reestablish a session. \n```java\nclient.setCredentialsPath(\"credentials.json\"); // Optional - It defaults to \"credentials.json\"\n```\nAfter a session has been successfully initialized, a qr code must be scanned from the device where WhatsApp is running on. To print a QR code in the console, call the setPrintQRCode() method:\n```java\nclient.setPrintQRCode(true);\n```\nTo learn how to receive the qr code as BufferedImage please refer to \"Message handlers\".\n\n## Complete example\n```java\nWAClient client = new WAClient();\nclient.setPrintQRCode(true);\nclient.addClientActionListener(new ClientActionListener() {\n\t@Override\n\tpublic void onQRCodeScanRequired(BufferedImage img) {\n\t\tSystem.out.println(\"Authentication required! Please scan the QR code!\");\n\t}\n});\nint httpCode = client.openConnection();\nif(httpCode == 200) {\n\tSystem.out.println(\"Logged in successfully!\");\n\tSystem.out.println(\"You have \" + client.loadChats().length + \" chats\");\n} else {\n\tSystem.out.println(\"Login failed! Code: \" + httpCode);\n}\n```\n\n## Message handlers\nAfter a WAClient instance is initialized, the `addClientActionListener` method can be called to register a `ClientActionInterface` and receive a number of callbacks. `ClientActionListener` is an empty implementation of `ClientActionInterface` interface.\n\n- Called when a new qr code has been generated and has to be scanned for login. A qr code has a lifetime of 20 second sand up to 5 five new ones can be created.\n```java\nclient.addClientActionListener(new ClientActionListener() {\n    @Override\n    public void onQRCodeScanRequired(BufferedImage img) {\n        save(img);\n    }\n    \n    // ...\n});\n```\n- Called if the login was successful (Code: 200) or an error occurred.\n```java\n@Override\npublic void onReceiveLoginResponse(int httpCode) {\n    if(httpCode == 200) {\n        System.out.println(\"Logged in successfully!);\n    } else {\n        System.out.println(\"Login failed! Code: \" + httpCode);\n    }\n}\n```\n- Other callbacks defined in `ClientActionInterface` interface:\n```java\n@Override\npublic void onWAMessage(WAMessage[] waMessage) {\n    // ...\n}\n\n@Override\npublic void onWAChat(WAChat[] chats) {\n    // ...\n}\n\t\t\t\n@Override\npublic void onWAContact(WAContact[] contacts) {\n    // ...\n}\n\t\t\t\n@Override\npublic void onWAEmoji(WAEmoji[] emojis) {\n    // ...\n}\n```\n## Sending messages\n```java\nString remoteJid = \"0123456789@s.whatsapp.net\";\n\nclient.sendMessage(remoteJid, \"Hello World\");\n```\n**Note**:\n- WhatsApp identifies a person or a group with a unique chat identification called `jid`.\n- Chats: `[country code][phone number]@s.whatsapp.net`, for example `490123456789@s.whatsapp.net`\n- Groups: `[phone number of group creator]-[timestamp of group creation]@g.us`, e.g. `490123456789-1596766695@g.us`\n\n## Deleting messages\nLets you delete a sent message for yourself\n```java\nString remoteJid = \"0123456789@s.whatsapp.net\";\nString messageId = \"3EM04B5BA7A366D3F9AE\";\nboolean owner = true;\n\t\t\t\t\t\nclient.clearMessage(remoteJid, messageId, owner);\n```\n\n## Loading messages\nQueries the chat history of a conversation \n```java\n// Query the last 25 messages\nWAMessage[] waMessages = client.loadChatHistory(remoteJid, 25);\n```\nQueries the chat history after a certain message\n```java\n// Query the last 25 messages after the message with the id x, which I'm not the owner of\nWAMessage[] waMessages = client.loadChatHistory(remoteJid, 25, \"4C739872E8K15F7L0ACB\", false);\n```\nWhen you query the messages of a chat, you get an array of WAMessage objects, which in turn can contain different types of message types. To determine which type it is, the methods ```waMessage.hasImageMessage()```, ```waMessage.hasVideoMessage()```, ```waMessage.hasConversationMessage()``` and ```waMessage.hasStubMessage()``` can be used. \nFor example:\n```java\nWAMessage[] waMessages = client.loadChatHistory(\"490123456789@s.whatsapp.net\", 25);\nfor(WAMessage message : waMessages) {\n\tif(message.hasConversationMessage()) {\n\t\tSystem.out.println(message.getConversationMessage().getText());\n\t} else if(message.hasImageMessage()) {\n\t\tBufferedImage img = message.getImageMessage().getJpegFullResolution();\n\t\t// ...\n\t}\n}\n```\n\n## Loading chats\nLoads direct and group chats\n```java\nWAChat[] waChats = client.loadChats();\n```\n\n## Loading contacts\nQueries your WhatsApp contacts\n```java\nWAContact[] waContacts = client.loadContacts();\n```\n\n## Misc\nTo get recently used emojis and their relative frequency of use\n```java\nWAEmoji[] waEmojis = client.loadEmojis();\n```\nTo get the displayed picture of some person or group\n```java\nBufferedImage img = client.getChatPicture(\"abc@c.us\");\n```\nTo get the status of some person\n```java\nString status = client.getStatus(\"abc@c.us\");\n```\nTo get someone's presence (if they're typing, online) \n```java\nString presence = client.requestPresenceUpdate(\"abc@c.us\");\n```\nTo set your global presence status\n```java\nclient.updatePresence(Presence.AVAILABLE);\n// Others: Presence.UNAVAILABLE, Presence.COMPOSING, Presence.RECORDING, Presence.PAUSED\n```\n\n## Objects\n- **WAChat**:\n\n| Method        | Description   |\n| ------------- |---------------|\n| getJid        | Returns unique chat identification |\n| getName       | Returns your given contact name |\n| getUnreadMessages | Returns the amount of unread messages |\n| getLastInteraction | Returns the timestamp of the last message |\n| isMuted | Returns if the chat is muted |\n\n- **WAContact**:\n\n| Method        | Description   |\n| ------------- |---------------|\n| getJid        | Returns unique chat identification |\n| getName       | Returns the name your contact gave to WhatsApp |\n\n- **WAEmoji**:\n\n| Method        | Description   |\n| ------------- |---------------|\n| getCode       | Returns emoji code |\n| getValue      | Returns the frequency of use |\n\n- **WAConversationMessage**:\n\n| Method        | Description   |\n| ------------- |---------------|\n| getText | Returns content of the message |\n| hasQuotedTextMessage | Returns `true` if it contains a QuotedTextMessage |\n| getQuotedTextMessage | Returns QuotedTextMessage |\n\n- **QuotedTextMessage**:\n\n| Method        | Description   |\n| ------------- |---------------|\n| getText | Returns quote |\n\n- **WAImageMessage**:\n\n| Method        | Description   |\n| ------------- |---------------|\n| getMimetype | Returns mimetype of the image |\n| getCaption | Returns caption |\n| getJpegThumbnail | Returns a thumbnail of the image |\n| getJpegFullResolution | Returns the image with full resolution or null if it could not be loaded |\n| ... | ... |\n\n- **WAVideoMessage**:\n\n| Method        | Description   |\n| ------------- |---------------|\n| getMimetype | Returns mimetype of the video |\n| getSeconds | Returns video length |\n| getMp4Thumbnail | Returns a thumbnail of the video |\n| getMp4FullResolution | Returns the video with full resolution or null if it could not be loaded |\n| ... | ... |\n\n- **WAMessage**:\n\n| Method        | Description   |\n| ------------- |---------------|\n| getRemoteJid | Returns unique chat identification |\n| getId | Returns the id of a message |\n| getFromMe | Returns `true` if the message is from you |\n| getMessageTimestamp | Returns the message timestamp |\n| getStatus | Returns the status of the message |\n| getImageMessage |\n| getConversationMessage |\n| getVideoMessage |\n| getStubMessage |\n| ... | ... |\n\n**Note**: Audio and document messages are not implemented\n\n## Legal\nThis code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouuke%2Fwhatsjava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flouuke%2Fwhatsjava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouuke%2Fwhatsjava/lists"}