-
Notifications
You must be signed in to change notification settings - Fork 6.9k
feat(evohub): registra webhook inbound no hub durante o link-existing #2636
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
Merged
gomessguii
merged 6 commits into
develop
from
feat/EVO-2098-evohub-link-existing-webhook
Jul 13, 2026
+160
−2
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9095da7
feat(evohub): registra webhook inbound no hub durante o link-existing
489febf
fix(evohub): reactivate non-active hub webhooks and guard hub ids
gomessguii 7514a87
chore(evohub): merge develop to pick up the CI env fix from #2635
gomessguii 6379772
fix(evohub): rewrite the configured webhook secret when reusing a hub…
gomessguii 1230663
fix(evohub): inline the hub-id guard at each request sink
gomessguii 49bbdfe
docs(evohub): write the comments this branch adds in English
gomessguii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -52,6 +52,15 @@ | |
| meta_connection?: HubMetaConnection | null; | ||
| } | ||
|
|
||
| // Webhook do hub (WebhookResponse — webhook.go:116). Só os campos que usamos. | ||
| export interface HubWebhookInfo { | ||
| id: string; | ||
| name?: string; | ||
| url: string; | ||
| status?: string; | ||
| all_channels?: boolean; | ||
| } | ||
|
|
||
| // ---- Criar-novo (POST /api/v1/channels) ---- | ||
| export interface HubProvisionRequest { | ||
| name: string; | ||
|
|
@@ -143,7 +152,7 @@ | |
| * server-side; o front NUNCA vê o token. | ||
| */ | ||
| async getChannel(id: string): Promise<HubChannel> { | ||
| const { data } = await this.http.get(`/channels/${id}`); | ||
Check failureCode scanning / CodeQL Server-side request forgery Critical
The
URL Error loading related location Loading user-provided value Error loading related location Loading The URL Error loading related location Loading |
||
| return data; | ||
| } | ||
|
|
||
|
|
@@ -155,6 +164,65 @@ | |
| return this.listChannels(type); | ||
| } | ||
|
|
||
| // ---- Webhooks (inbound do hub -> evolution-api) ---- | ||
|
|
||
| /** Webhooks já ASSOCIADOS ao canal: GET /api/v1/channels/:id/webhooks → { webhooks, count }. */ | ||
| async listChannelWebhooks(channelId: string): Promise<HubWebhookInfo[]> { | ||
| const { data } = await this.http.get(`/channels/${channelId}/webhooks`); | ||
Check failureCode scanning / CodeQL Server-side request forgery Critical
The
URL Error loading related location Loading user-provided value Error loading related location Loading |
||
| return this.normalizeWebhookList(data); | ||
| } | ||
|
|
||
| /** Todos os webhooks do usuário da API-key: GET /api/v1/webhooks. */ | ||
| async listWebhooks(): Promise<HubWebhookInfo[]> { | ||
| const { data } = await this.http.get('/webhooks'); | ||
| return this.normalizeWebhookList(data); | ||
| } | ||
|
|
||
| private normalizeWebhookList(data: any): HubWebhookInfo[] { | ||
| if (Array.isArray(data)) return data; | ||
| if (Array.isArray(data?.webhooks)) return data.webhooks; | ||
| if (Array.isArray(data?.data)) return data.data; | ||
| return []; | ||
| } | ||
|
|
||
| /** POST /api/v1/webhooks/:id/associate — associa um webhook existente ao canal. */ | ||
| async associateWebhook(webhookId: string, channelId: string): Promise<void> { | ||
| await this.http.post(`/webhooks/${webhookId}/associate`, { channel_id: channelId }); | ||
| } | ||
|
|
||
| /** | ||
| * Garante (idempotente) que o canal tem um webhook ativo apontando para | ||
| * `webhookUrl` — o caminho single-shot do provision não existe no link-existing, | ||
| * e sem webhook o canal envia mas nunca RECEBE mensagens. Ordem: | ||
| * 1) já associado ao canal com a mesma URL → no-op; | ||
| * 2) webhook do usuário com a mesma URL → associa (evita duplicar; um webhook | ||
| * all_channels com a URL já cobre o canal, também no-op); | ||
| * 3) cria novo com `channels: [channelId]` (single-shot) e `events: []` | ||
| * (vazio = TODOS os eventos — webhook_service.go:98). Secret = recipe | ||
| * register-with-own-secret, igual ao provision. | ||
| */ | ||
| async ensureChannelWebhook(channelId: string, webhookUrl: string): Promise<void> { | ||
| const associated = await this.listChannelWebhooks(channelId); | ||
| if (associated.some((w) => w.url === webhookUrl && w.status !== 'inactive')) return; | ||
|
|
||
| const all = await this.listWebhooks(); | ||
| const existing = all.find((w) => w.url === webhookUrl && w.status !== 'inactive'); | ||
| if (existing) { | ||
| if (!existing.all_channels) await this.associateWebhook(existing.id, channelId); | ||
| return; | ||
| } | ||
|
|
||
| const cfg = this.configService.get<EvolutionHub>('EVOLUTION_HUB'); | ||
| const body: Record<string, any> = { | ||
| name: 'evolution-api inbound', | ||
| url: webhookUrl, | ||
| events: [], | ||
| channels: [channelId], | ||
| }; | ||
| if (cfg.WEBHOOK_SECRET) body.secret = cfg.WEBHOOK_SECRET; | ||
| await this.http.post('/webhooks', body); | ||
| } | ||
|
|
||
| // ---- Fase 2 ---- | ||
|
|
||
| /** | ||
|
|
@@ -203,7 +271,7 @@ | |
| * Evolution; 'byo' exige channel_credentials no hub. | ||
| */ | ||
| async connectToMeta(channelId: string, req: MetaConnectRequest): Promise<MetaConnectResponse> { | ||
| const { data } = await this.http.post(`/channels/${channelId}/meta-connect`, req); | ||
Check failureCode scanning / CodeQL Server-side request forgery Critical
The
URL Error loading related location Loading user-provided value Error loading related location Loading |
||
| return data; | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.