Skip to content

Commit 8744fba

Browse files
committed
fix: client should be initiate at the end of program
Signed-off-by: sarthakjdev <jsarthak448@gmail.com>
1 parent 4a65023 commit 8744fba

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

packages/create-wapi-bot/template/javascript/src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ function loadEventListeners() {
1313

1414
async function init() {
1515
loadEventListeners();
16-
await client.initiate();
17-
// send a message to a number
1816
await whatsappClient.message.send({
1917
message: new TextMessage({ text: "hello, world!" }),
2018
phoneNumber: "<replace-me>",
2119
});
20+
client.initiate();
2221
}
2322

2423
process.on("unhandledRejection", (error) => {
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { type TextMessageEvent } from '@wapijs/wapi.js'
1+
import { type TextMessageEvent, TextMessage } from '@wapijs/wapi.js'
22

33
export default async function (message: TextMessageEvent) {
44
console.log(message)
55
await message.reply({
6-
6+
message: new TextMessage({
7+
text: "Hello, World!",
8+
}),
79
})
810
}

packages/create-wapi-bot/template/typescript/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ async function loadEventListeners() {
1111

1212
async function init() {
1313
loadEventListeners()
14-
await whatsappClient.initiate()
15-
1614
// send a message to a number
1715
await whatsappClient.message.send({
1816
message: new TextMessage({ text: 'hello, world!' }),
1917
phoneNumber: '<replace-me>'
2018
})
19+
await whatsappClient.initiate()
2120
}
2221

2322
init().catch(error => console.error(error))
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
WHATSAPP_API_ACCESS_TOKEN=EABhCftGVaeIBOza2qZAuUttZCpiFJAVj9titVTRuYB0J17ty6aglC8nuDIHFoYMC2GZC7yP39ZCUlfzqcKcgk8ZCONYWnZAA4YDkyOcDY33qLZAHuic0jIKttDKoY3iDhfetZACVdbEr8bbtJ0FJRKFIQRDuRQdPxmQpxVrLUkR8ZBJ7tB3jTNYuWyEJhNy7AGXgukAZAtch7K1iRE0s0ywyvguslGcZBxbtx2GIBi8mkF33K0ZD
2-
WHATSAPP_PHONE_NUMBER_ID=113269274970227
3-
WHATSAPP_BUSINESS_ACCOUNT_ID=103043282674158
4-
WHATSAPP_WEBHOOK_SECRET=1234567890
1+
WHATSAPP_API_ACCESS_TOKEN=
2+
WHATSAPP_PHONE_NUMBER_ID=
3+
WHATSAPP_BUSINESS_ACCOUNT_ID=
4+
WHATSAPP_WEBHOOK_SECRET=

0 commit comments

Comments
 (0)