Skip to content

Commit 3f1452a

Browse files
tanviet12claude
andcommitted
fix: extract Zalo attachment URLs and use backend OAuth flow
- zalo_oa.go: extract image/file/sticker/gif attachment URLs from Zalo messages - Channels.vue: use backend /reauth API for signed OAuth URL instead of hardcoded frontend redirect Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 82a7378 commit 3f1452a

2 files changed

Lines changed: 49 additions & 8 deletions

File tree

backend/channels/zalo_oa.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,39 @@ func (z *ZaloOAAdapter) FetchMessages(ctx context.Context, conversationID string
280280
RawData: msg,
281281
}
282282

283-
// Check for attachments
283+
// Check for attachments (image, file, sticker, gif, etc.)
284284
if msgType, ok := msg["type"].(string); ok && msgType != "text" {
285285
syncedMsg.ContentType = msgType
286+
287+
// Extract attachment URL from Zalo message
288+
aURL := ""
289+
aName := ""
290+
if u, ok := msg["url"].(string); ok && u != "" {
291+
aURL = u
292+
} else if u, ok := msg["thumb"].(string); ok && u != "" {
293+
aURL = u
294+
}
295+
// For file type: check links array
296+
if links, ok := msg["links"].([]interface{}); ok && len(links) > 0 {
297+
if link, ok := links[0].(map[string]interface{}); ok {
298+
if u, ok := link["url"].(string); ok {
299+
aURL = u
300+
}
301+
if n, ok := link["name"].(string); ok {
302+
aName = n
303+
}
304+
}
305+
}
306+
if aURL != "" {
307+
if aName == "" {
308+
aName = fmt.Sprintf("%s-%s", msgType, msgID)
309+
}
310+
syncedMsg.Attachments = append(syncedMsg.Attachments, Attachment{
311+
Type: msgType,
312+
URL: aURL,
313+
Name: aName,
314+
})
315+
}
286316
}
287317

288318
messages = append(messages, syncedMsg)

frontend/src/views/Channels.vue

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,26 @@ async function createAndAuthZalo() {
247247
})
248248
showDialog.value = false
249249
250-
// Step 2: Redirect to Zalo OAuth authorize URL
250+
// Step 2: Use backend reauth API to get signed OAuth URL (with HMAC state)
251251
const channelId = created?.id || created?.data?.id
252+
if (channelId && newChannel.channel_type === 'zalo_oa') {
253+
try {
254+
const { data: reauthData } = await api.post(`/tenants/${tenantId.value}/channels/${channelId}/reauth`)
255+
const redirectUrl = reauthData?.redirect_url
256+
if (redirectUrl) {
257+
window.location.href = redirectUrl
258+
return
259+
}
260+
} catch {
261+
// Fallback: redirect to channel detail
262+
router.push(`/${tenantId.value}/channels/${channelId}`)
263+
return
264+
}
265+
}
266+
showSnack(t('success'), 'success')
267+
channelStore.fetchChannels(tenantId.value)
252268
if (channelId) {
253-
const callbackUrl = `${window.location.origin}/api/v1/channels/zalo/callback`
254-
const authUrl = `https://oauth.zaloapp.com/v4/oa/permission?app_id=${newChannel.creds.app_id}&redirect_uri=${encodeURIComponent(callbackUrl)}&state=${tenantId.value}:${channelId}`
255-
window.location.href = authUrl
256-
} else {
257-
showSnack(t('success'), 'success')
258-
channelStore.fetchChannels(tenantId.value)
269+
router.push(`/${tenantId.value}/channels/${channelId}`)
259270
}
260271
261272
newChannel.name = ''

0 commit comments

Comments
 (0)