H-116: close visitor payload trust boundaries (#19)

* H-116: close visitor payload trust boundaries

* H-129: unblock SQLite backend tests

* H-129: remove stale last-seen response assertions

---------

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-15 01:15:04 +08:00
committed by GitHub
co-authored by rogee
parent 55fac96700
commit 18ecee3e46
9 changed files with 211 additions and 16 deletions
@@ -294,7 +294,8 @@ func agentBotWebhookPayload(eventType string, accountID uint, inboxID uint, data
if _, ok := payload["inbox_id"]; !ok {
payload["inbox_id"] = inboxID
}
return payload
sanitized, _ := webhookutil.SanitizeOutbound(payload).(map[string]interface{})
return sanitized
}
// pushToBot sends the webhook payload to a single bot's outgoing_url with Chatwoot webhook headers.
@@ -106,10 +106,15 @@ func TestAgentBotListenerSendsChatwootStyleTopLevelPayload(t *testing.T) {
listener := NewAgentBotListener(repository.NewAgentBotInboxRepo(db), repository.NewAgentBotRepo(db), nil, nil)
err := listener.HandleEvent(context.Background(), "message_created", account.ID, inbox.ID, map[string]interface{}{
"id": float64(123),
"content": "hello bot",
"id": float64(123),
"content": "hello bot",
"sender_id": float64(7),
"sender_type": "AgentBot",
"ai_takeover_active": true,
"content_attributes": []interface{}{map[string]interface{}{"business": "keep", "sender_name": "Captain"}},
"conversation": map[string]interface{}{
"id": float64(456),
"id": float64(456),
"assignee_agent_bot_id": float64(8),
},
})
require.NoError(t, err)
@@ -122,6 +127,13 @@ func TestAgentBotListenerSendsChatwootStyleTopLevelPayload(t *testing.T) {
assert.Equal(t, "hello bot", received["content"])
assert.NotContains(t, received, "data")
assert.NotContains(t, received, "timestamp")
assert.NotContains(t, string(receivedBody), "AgentBot")
assert.NotContains(t, string(receivedBody), "Captain")
assert.NotContains(t, string(receivedBody), "sender_")
assert.NotContains(t, string(receivedBody), "ai_takeover_")
assert.NotContains(t, string(receivedBody), "assignee_agent_bot_id")
attributes := received["content_attributes"].([]interface{})
assert.Equal(t, map[string]interface{}{"business": "keep"}, attributes[0])
assert.NotEmpty(t, receivedDelivery)
assert.Regexp(t, `^\d+$`, receivedTimestamp)
mac := hmac.New(sha256.New, []byte("secret"))