[go: nahoru, domu]

Skip to content

Commit

Permalink
added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ookamiiixd committed May 27, 2022
1 parent 345860d commit 7e3260e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/authenticating.js
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
}
})()
50 changes: 50 additions & 0 deletions examples/sending-message.js
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!',
},
})
})()

0 comments on commit 7e3260e

Please sign in to comment.