Skip to content

Commit 910804d

Browse files
author
Sergey Sysalov
committed
payload-формат contact и обновил конвертер: теперь ContactAttachment разбирается из attachments[].payload.vcf_info/max_info/hash
1 parent bd5f230 commit 910804d

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/Max.Bot/Types/Converters/AttachmentJsonConverter.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class AttachmentJsonConverter : JsonConverter<Attachment>
5353

5454
if (IsType(typeString, AttachmentTypeNames.Contact))
5555
{
56-
return JsonSerializer.Deserialize<ContactAttachment>(root.GetRawText(), options);
56+
return DeserializeContactAttachment(root, options);
5757
}
5858

5959
if (IsType(typeString, AttachmentTypeNames.Video))
@@ -184,6 +184,22 @@ public override void Write(Utf8JsonWriter writer, Attachment value, JsonSerializ
184184
return JsonSerializer.Deserialize<PhotoAttachment>(root.GetRawText(), options);
185185
}
186186

187+
private static ContactAttachment? DeserializeContactAttachment(JsonElement root, JsonSerializerOptions options)
188+
{
189+
if (root.TryGetProperty("payload", out var payload) && payload.ValueKind == JsonValueKind.Object)
190+
{
191+
var attachment = JsonSerializer.Deserialize<ContactAttachment>(payload.GetRawText(), options);
192+
if (attachment != null)
193+
{
194+
// Ensure type is always set even when payload does not include it.
195+
attachment.Type = AttachmentTypeNames.Contact;
196+
}
197+
return attachment;
198+
}
199+
200+
return JsonSerializer.Deserialize<ContactAttachment>(root.GetRawText(), options);
201+
}
202+
187203
private static T? DeserializeMediaAttachment<T>(JsonElement root, string payloadPropertyName, JsonSerializerOptions options)
188204
where T : Attachment
189205
{

0 commit comments

Comments
 (0)