feat: add webhook thought ingestion
This commit is contained in:
@@ -53,6 +53,7 @@ func Normalize(in thoughttypes.ThoughtMetadata, capture config.CaptureConfig) th
|
||||
Type: normalizeType(in.Type),
|
||||
Source: normalizeSource(in.Source),
|
||||
Attachments: normalizeAttachments(in.Attachments),
|
||||
Webhook: normalizeWebhook(in.Webhook),
|
||||
MetadataStatus: normalizeMetadataStatus(in.MetadataStatus),
|
||||
MetadataUpdatedAt: strings.TrimSpace(in.MetadataUpdatedAt),
|
||||
MetadataLastAttemptedAt: strings.TrimSpace(in.MetadataLastAttemptedAt),
|
||||
@@ -201,10 +202,31 @@ func Merge(base, patch thoughttypes.ThoughtMetadata, capture config.CaptureConfi
|
||||
if len(patch.Attachments) > 0 {
|
||||
merged.Attachments = append(append([]thoughttypes.ThoughtAttachment{}, merged.Attachments...), patch.Attachments...)
|
||||
}
|
||||
if patch.Webhook != nil {
|
||||
merged.Webhook = patch.Webhook
|
||||
}
|
||||
|
||||
return Normalize(merged, capture)
|
||||
}
|
||||
|
||||
func normalizeWebhook(value *thoughttypes.WebhookMetadata) *thoughttypes.WebhookMetadata {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
out := &thoughttypes.WebhookMetadata{
|
||||
ReceivedAt: strings.TrimSpace(value.ReceivedAt),
|
||||
IDempotencyKey: strings.TrimSpace(value.IDempotencyKey),
|
||||
ExternalID: strings.TrimSpace(value.ExternalID),
|
||||
}
|
||||
if len(value.SourceMetadata) > 0 {
|
||||
out.SourceMetadata = value.SourceMetadata
|
||||
}
|
||||
if out.ReceivedAt == "" && out.IDempotencyKey == "" && out.ExternalID == "" && len(out.SourceMetadata) == 0 {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func normalizeAttachments(values []thoughttypes.ThoughtAttachment) []thoughttypes.ThoughtAttachment {
|
||||
seen := make(map[string]struct{}, len(values))
|
||||
result := make([]thoughttypes.ThoughtAttachment, 0, len(values))
|
||||
|
||||
Reference in New Issue
Block a user