Skip to content

Commit e192a6d

Browse files
committed
previne override webhooks by chatwoot
1 parent 77d4053 commit e192a6d

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unoapi-cloud",
3-
"version": "2.2.2",
3+
"version": "2.2.3",
44
"description": "Unoapi Cloud",
55
"exports": "./dist/index.js",
66
"types": "./dist/index.d.ts",

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>
836836
};
837837
sessionData.webhooks.push(webhook);
838838
});
839-
839+
sessionData.overrideWebhooks = true
840840
fetch(`${apiUrl}/v15.0/${number}/register`, {
841841
method: 'POST',
842842
headers: {

src/services/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export type Config = {
7878
useS3: boolean
7979
qrTimeoutMs: number
8080
label: string
81+
overrideWebhooks: boolean
8182
}
8283

8384
export const defaultConfig: Config = {
@@ -138,6 +139,7 @@ export const defaultConfig: Config = {
138139
useS3: false,
139140
qrTimeoutMs: 60000,
140141
label: '',
142+
overrideWebhooks: false
141143
}
142144

143145
export interface getConfig {

src/services/redis.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,12 @@ export const setConfig = async (phone: string, value: any) => {
289289
const currentConfig = await getConfig(phone)
290290
const key = configKey(phone)
291291
const currentWebhooks: Webhook[] = currentConfig && currentConfig.webhooks || []
292-
const newWebhooks: Webhook[] = value && value.webhooks || currentWebhooks
292+
const newWebhooks: Webhook[] = value && value.webhooks || []
293293
const updatedWebooks: Webhook[] = []
294-
newWebhooks.forEach(n => {
295-
const c = currentWebhooks.find((c) => c.id === n.id)
294+
const baseWebhook = value.overrideWebhooks ? newWebhooks : currentWebhooks
295+
const searchWebhooks = value.overrideWebhooks ? currentWebhooks : newWebhooks
296+
baseWebhook.forEach(n => {
297+
const c = searchWebhooks.find((c) => c.id === n.id)
296298
if (c) {
297299
updatedWebooks.push({ ...c, ...n })
298300
} else {
@@ -301,6 +303,7 @@ export const setConfig = async (phone: string, value: any) => {
301303
})
302304
value.webhooks = updatedWebooks
303305
const config = { ...currentConfig, ...value }
306+
delete config.overrideWebhooks
304307
await redisSetAndExpire(key, JSON.stringify(config), SESSION_TTL)
305308
configs.delete(phone)
306309
return config

0 commit comments

Comments
 (0)