forked from ookamiiixd/baileys-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
345860d
commit 7e3260e
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const BASE_URI = 'http://localhost:8000/' | ||
const SESSION_ID = 'john' | ||
|
||
const sendRequest = async () => { | ||
// Here we are using fetch API to send the request | ||
// eslint-disable-next-line no-undef | ||
const response = await fetch(`${BASE_URI}sessions/add`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
id: SESSION_ID, | ||
// A string value representing the client type. | ||
// Use 'false' for Multi-Device, | ||
// or 'true' for Legacy (Normal WhatsApp Web). | ||
// This is important since the generated QR is not compatible each other. | ||
// So make sure you generated the correct one. | ||
isLegacy: 'false', | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
|
||
return response.json() | ||
} | ||
|
||
;(async () => { | ||
const response = await sendRequest() | ||
|
||
if (response.success && 'qr' in response.data) { | ||
// Scan the QR | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const BASE_URI = 'http://localhost:8000/' | ||
const SESSION_ID = 'john' | ||
|
||
const sendMessage = async (endpoint, data) => { | ||
// Here we are using fetch API to send the request | ||
// eslint-disable-next-line no-undef | ||
const response = await fetch(`${BASE_URI}${endpoint}?id=${SESSION_ID}`, { | ||
method: 'POST', | ||
body: JSON.stringify(data), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
|
||
return response.json() | ||
} | ||
|
||
;(async () => { | ||
// Send Text Message to Someone | ||
await sendMessage('chats/send', { | ||
receiver: '628231xxxxx', | ||
message: { | ||
text: 'Hello there!', | ||
}, | ||
}) | ||
|
||
// Send Bulk Text Message to Multiple Person | ||
await sendMessage('chats/send-bulk', [ | ||
{ | ||
receiver: '628231xxxxx', | ||
message: { | ||
text: 'Hello! How are you?', | ||
}, | ||
}, | ||
{ | ||
receiver: '628951xxxxx', | ||
message: { | ||
text: "I'm fine, thank you.", | ||
}, | ||
}, | ||
]) | ||
|
||
// Send Text Message to a Group | ||
await sendMessage('groups/send', { | ||
receiver: '628950xxxxx-1631xxxxx', | ||
message: { | ||
text: 'Hello guys!', | ||
}, | ||
}) | ||
})() |