-
Notifications
You must be signed in to change notification settings - Fork 104
Log webhook #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Log webhook #7
Changes from all commits
d4b1af0
6605c93
d22dacc
8a2199f
807914b
fdd25e3
614e9f7
d425e22
b5b2028
8f61770
cbe095a
a9f1b5a
e153b75
2e3ba3a
7297e27
98064cc
0e5572f
3d50534
bc2c96f
dc30002
d41cedf
114f879
3a28019
ec6612a
01492cb
a85e3ab
15fc87b
b68b30f
d39c162
4a144ac
4ae74fe
d983921
73594af
4c14273
998a4f0
9d546aa
c56a0d3
07bd901
b0d0bc4
11eb51d
3fa1a5f
2b1060c
d642cdc
b8fd741
c0fd917
12d4c07
340a19a
6ed2300
39e6a4b
e6b637a
9e23c38
f21f93e
b1e8a3e
c6748f8
77c0d96
775a504
be0bfa4
3c723aa
3ba25d5
0460d72
aa1c6df
2273fbd
970ded7
0113243
2b973a1
64efef6
582cd91
85b4136
bec40b3
a9e27a0
f4594ee
fbc9337
d6d246b
d094595
dff9c8a
917e60b
7b6438a
183c88d
bd47e9b
a62edbc
ab1d802
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Instance" ADD COLUMN "webVersion" VARCHAR(50); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- CreateIndex | ||
CREATE INDEX "IsOnWhatsapp_remoteJid_idx" ON "IsOnWhatsapp"("remoteJid"); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -131,7 +131,8 @@ export class InstanceController { | |||||||||||||||||||||||||||||||||
throw new BadRequestException('number is required'); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL; | ||||||||||||||||||||||||||||||||||
webhookWaBusiness = `${urlServer}/webhook/meta`; | ||||||||||||||||||||||||||||||||||
const webHookTest = this.configService.get<WaBusiness>('WA_BUSINESS').WEBHOOK_TEST; | ||||||||||||||||||||||||||||||||||
webhookWaBusiness = `${webHookTest ? webHookTest : urlServer}/webhook/meta`; | ||||||||||||||||||||||||||||||||||
accessTokenWaBusiness = this.configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
@@ -285,6 +286,32 @@ export class InstanceController { | |||||||||||||||||||||||||||||||||
return this.waMonitor.instanceInfo(instanceNames); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public async getInstanceByName({ instanceName }: InstanceDto) { | ||||||||||||||||||||||||||||||||||
const instanceByName = await this.prismaRepository.instance.findFirst({ | ||||||||||||||||||||||||||||||||||
where: { | ||||||||||||||||||||||||||||||||||
name: instanceName, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (!instanceByName) { | ||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
const response = { | ||||||||||||||||||||||||||||||||||
id: instanceByName.id, | ||||||||||||||||||||||||||||||||||
name: instanceByName.name, | ||||||||||||||||||||||||||||||||||
ownerJid: instanceByName.ownerJid, | ||||||||||||||||||||||||||||||||||
connectionStatus: instanceByName.connectionStatus, | ||||||||||||||||||||||||||||||||||
profileName: instanceByName.profileName, | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return response; | ||||||||||||||||||||||||||||||||||
Comment on lines
+300
to
+307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Inline variable that is immediately returned (
Suggested change
ExplanationSomething that we often see in people's code is assigning to a result variableand then immediately returning it. Returning the result directly shortens the code and removes an unnecessary Where intermediate variables can be useful is if they then get used as a |
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public async countInstances() { | ||||||||||||||||||||||||||||||||||
const count = await this.prismaRepository.instance.count(); | ||||||||||||||||||||||||||||||||||
return count; | ||||||||||||||||||||||||||||||||||
Comment on lines
+311
to
+312
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Inline variable that is immediately returned (
Suggested change
ExplanationSomething that we often see in people's code is assigning to a result variableand then immediately returning it. Returning the result directly shortens the code and removes an unnecessary Where intermediate variables can be useful is if they then get used as a |
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) { | ||||||||||||||||||||||||||||||||||
return await this.waMonitor.waInstances[instanceName].setPresence(data); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,17 @@ export class MetaRouter extends RouterBroker { | |||||||||||||||
const { body } = req; | ||||||||||||||||
const response = await metaController.receiveWebhook(body); | ||||||||||||||||
|
||||||||||||||||
return res.status(200).json(response); | ||||||||||||||||
}) | ||||||||||||||||
.get(this.routerPath('webhook/whatsapp', false), async (req, res) => { | ||||||||||||||||
if (req.query['hub.verify_token'] === configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK) | ||||||||||||||||
res.send(req.query['hub.challenge']); | ||||||||||||||||
else res.send('Error, wrong validation token'); | ||||||||||||||||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Use block braces for ifs, whiles, etc. (
Suggested change
ExplanationIt is recommended to always use braces and create explicit statement blocks.Using the allowed syntax to just write a single statement can lead to very confusing |
||||||||||||||||
}) | ||||||||||||||||
.post(this.routerPath('webhook/whatsapp', false), async (req, res) => { | ||||||||||||||||
const { body } = req; | ||||||||||||||||
const response = await metaController.receiveWebhook(body); | ||||||||||||||||
|
||||||||||||||||
return res.status(200).json(response); | ||||||||||||||||
}); | ||||||||||||||||
} | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Avoid unneeded ternary statements (
simplify-ternary
)Explanation
It is possible to simplify certain ternary statements into either use of an||
or!
.This makes the code easier to read, since there is no conditional logic.