Skip to content

Commit

Permalink
feat: support new properties on Messages Webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 27, 2024
1 parent 426ef47 commit 02044e5
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"client_ref": "string",
"message_type": "audio",
"audio": {
"url": "https://example.com/audio.mp3"
"url": "https://example.com/audio.mp3",
"name": "audio.mp3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"client_ref": "string",
"message_type": "image",
"image": {
"url": "https://example.com/image.jpg"
"url": "https://example.com/image.jpg",
"name": "image.jpg"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"timestamp": "2020-01-01T14:00:00.000Z",
"client_ref": "string",
"message_type": "text",
"text": "This is sample text."
"text": "This is sample text.",
"origin": {
"network_code": "12345"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"client_ref": "string",
"message_type": "vcard",
"vcard": {
"url": "https://example.com/conatact.vcf"
"url": "https://example.com/conatact.vcf",
"name": "contact.vcf"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"client_ref": "string",
"message_type": "video",
"video": {
"url": "https://example.com/video.mp4"
"url": "https://example.com/video.mp4",
"name": "video.mp4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"usage": {
"currency": "EUR",
"price": "0.0333"
},
"origin": {
"network_code": "12345"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"client_ref": "string",
"message_type": "image",
"image": {
"url": "https://example.com/image.jpg"
"url": "https://example.com/image.jpg",
"name": "image.jpg"
}
}
7 changes: 7 additions & 0 deletions Vonage.Test/Messages/Webhooks/SerializationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public class SerializationTest
Audio = new UrlDetails
{
Url = "https://example.com/audio.mp3",
Name = "audio.mp3",
},
});

Expand All @@ -167,6 +168,7 @@ public class SerializationTest
Image = new UrlDetails
{
Url = "https://example.com/image.jpg",
Name = "image.jpg",
},
});

Expand All @@ -185,6 +187,7 @@ public class SerializationTest
ClientReference = "string",
MessageType = "text",
Text = "This is sample text.",
Origin = new Origin("12345"),
});

[Fact]
Expand All @@ -204,6 +207,7 @@ public class SerializationTest
Vcard = new UrlDetails
{
Url = "https://example.com/conatact.vcf",
Name = "contact.vcf",
},
});

Expand All @@ -224,6 +228,7 @@ public class SerializationTest
Video = new UrlDetails
{
Url = "https://example.com/video.mp4",
Name = "video.mp4",
},
});

Expand Down Expand Up @@ -251,6 +256,7 @@ public class SerializationTest
Currency = "EUR",
Price = "0.0333",
},
Origin = new Origin("12345"),
});

[Fact]
Expand Down Expand Up @@ -433,6 +439,7 @@ public class SerializationTest
Image = new UrlDetails
{
Url = "https://example.com/image.jpg",
Name = "image.jpg",
},
});

Expand Down
95 changes: 64 additions & 31 deletions Vonage/Messages/Webhooks/MessageWebhookResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct MessageWebhookResponse
/// Channel specific metadata for Audio.
/// </summary>
public UrlDetails? Audio { get; set; }

/// <summary>
/// The channel the message came in on.
/// </summary>
Expand All @@ -21,28 +21,29 @@ public struct MessageWebhookResponse
/// <summary>
/// Client reference of up to 100 characters. The reference will be present in every message status.
/// </summary>
[JsonPropertyName("client_ref")] public string ClientReference { get; set; }
[JsonPropertyName("client_ref")]
public string ClientReference { get; set; }

/// <summary>
/// This is only present for the Inbound Message where the user is quoting another message. It provides information about the quoted message and/or the product message being responded to.
/// </summary>
public ContextDetails? Context { get; set; }

/// <summary>
/// Channel specific metadata for File.
/// </summary>
public UrlDetails? File { get; set; }

/// <summary>
/// The phone number of the message sender in the E.164 format. Don't use a leading + or 00 when entering a phone number, start with the country code, for example, 447700900000. For SMS in certain localities alpha-numeric sender id's will work as well, see <see href="https://developer.vonage.com/en/messaging/sms/guides/country-specific-features#country-specific-features">Global Messaging</see> for more details.
/// </summary>
public string From { get; set; }

/// <summary>
/// Channel specific metadata for Image.
/// </summary>
public UrlDetails? Image { get; set; }

/// <summary>
/// Channel specific metadata for Location.
/// </summary>
Expand All @@ -51,18 +52,20 @@ public struct MessageWebhookResponse
/// <summary>
/// The type of message to send. You must provide text in this field.
/// </summary>
[JsonPropertyName("message_type")] public string MessageType { get; set; }
[JsonPropertyName("message_type")]
public string MessageType { get; set; }

/// <summary>
/// The UUID of the message.
/// </summary>
[JsonPropertyName("message_uuid")] public Guid MessageUuid { get; set; }
[JsonPropertyName("message_uuid")]
public Guid MessageUuid { get; set; }

/// <summary>
/// Channel specific metadata for Order.
/// </summary>
public OrderDetails? Order { get; set; }

/// <summary>
/// Represents the profile details.
/// </summary>
Expand All @@ -71,28 +74,29 @@ public struct MessageWebhookResponse
/// <summary>
/// A message from the channel provider, which may contain a description, error codes or other information.
/// </summary>
[JsonPropertyName("provider_message")] public string ProviderMessage { get; set; }
[JsonPropertyName("provider_message")]
public string ProviderMessage { get; set; }

/// <summary>
/// Channel specific metadata for Reply.
/// </summary>
public ReplyDetails? Reply { get; set; }

/// <summary>
/// Channel specific metadata for SMS.
/// </summary>
public SmsDetails? Sms { get; set; }

/// <summary>
/// Channel specific metadata for Sticker.
/// </summary>
public UrlDetails? Sticker { get; set; }

/// <summary>
/// The UTF-8 encoded text of the inbound message.
/// </summary>
public string Text { get; set; }

/// <summary>
/// The datetime of when the event occurred, in ISO 8601 format.
/// </summary>
Expand All @@ -102,21 +106,25 @@ public struct MessageWebhookResponse
/// The phone number of the message recipient in the E.164 format. Don't use a leading + or 00 when entering a phone number, start with the country code, for example, 447700900000.
/// </summary>
public string To { get; set; }

/// <summary>
/// Represents details about message usage.
/// </summary>
public UsageDetails? Usage { get; set; }

/// <summary>
/// Channel specific metadata for Vcard.
/// </summary>
public UrlDetails? Vcard { get; set; }

/// <summary>
/// Channel specific metadata for Video.
/// </summary>
public UrlDetails? Video { get; set; }

/// <summary>
/// </summary>
public Origin Origin { get; set; }
}

/// <summary>
Expand All @@ -127,12 +135,14 @@ public struct OrderDetails
/// <summary>
/// The ID of the catalog containing the products in this order.
/// </summary>
[JsonPropertyName("catalog_id")] public string CatalogId { get; set; }
[JsonPropertyName("catalog_id")]
public string CatalogId { get; set; }

/// <summary>
/// The list of items.
/// </summary>
[JsonPropertyName("product_items")] public ProductItem[] ProductItems { get; set; }
[JsonPropertyName("product_items")]
public ProductItem[] ProductItems { get; set; }
}

/// <summary>
Expand All @@ -148,7 +158,8 @@ public struct ProductItem
/// <summary>
/// The unit price for this specific item.
/// </summary>
[JsonPropertyName("item_price")] public string ItemPrice { get; set; }
[JsonPropertyName("item_price")]
public string ItemPrice { get; set; }

/// <summary>
/// The ID of the specific product being ordered.
Expand All @@ -175,12 +186,14 @@ public struct LocationDetails
/// <summary>
/// Latitude of the location.
/// </summary>
[JsonPropertyName("lat")] public decimal Latitude { get; set; }
[JsonPropertyName("lat")]
public decimal Latitude { get; set; }

/// <summary>
/// Longitude of the location.
/// </summary>
[JsonPropertyName("long")] public decimal Longitude { get; set; }
[JsonPropertyName("long")]
public decimal Longitude { get; set; }

/// <summary>
/// Name of the location.
Expand All @@ -197,12 +210,12 @@ public struct ReplyDetails
/// A description that may be added to the interactive options presented (available only on interactive lists).
/// </summary>
public string Description { get; set; }

/// <summary>
/// An identifier to help identify the exact interactive message response.
/// </summary>
public string Id { get; set; }

/// <summary>
/// The title displayed on the interactive option chosen.
/// </summary>
Expand All @@ -222,12 +235,14 @@ public struct SmsDetails
/// <summary>
/// The number of inbound SMS messages concatenated together to comprise this message. SMS messages are 160 characters, if an inbound message exceeds that size they are concatenated together to forma single message. This number indicates how many messages formed this webhook.
/// </summary>
[JsonPropertyName("num_messages")] public string MessagesCount { get; set; }
[JsonPropertyName("num_messages")]
public string MessagesCount { get; set; }

/// <summary>
/// The number of inbound SMS messages concatenated together to comprise this message. SMS messages are 160 characters, if an inbound message exceeds that size they are concatenated together to forma single message. This number indicates how many messages formed this webhook.
/// </summary>
[JsonPropertyName("total_count")] public string TotalCount { get; set; }
[JsonPropertyName("total_count")]
public string TotalCount { get; set; }
}

/// <summary>
Expand All @@ -239,7 +254,7 @@ public struct UsageDetails
/// The charge currency in ISO 4217 format.
/// </summary>
public string Currency { get; set; }

/// <summary>
/// The charge amount as a stringified number.
/// </summary>
Expand All @@ -255,6 +270,14 @@ public struct UrlDetails
/// The publicly accessible URL of the attachment.
/// </summary>
public string Url { get; set; }

/// <summary>
/// </summary>
public string Name { get; set; }

/// <summary>
/// </summary>
public string Caption { get; set; }
}

/// <summary>
Expand All @@ -276,12 +299,14 @@ public struct ContextDetails
/// <summary>
/// The phone number of the original sender of the message being quoted in the E.164 format.
/// </summary>
[JsonPropertyName("message_from")] public string MessageFrom { get; set; }
[JsonPropertyName("message_from")]
public string MessageFrom { get; set; }

/// <summary>
/// The UUID of the message being quoted.
/// </summary>
[JsonPropertyName("message_uuid")] public string MessageUuid { get; set; }
[JsonPropertyName("message_uuid")]
public string MessageUuid { get; set; }

/// <summary>
/// An object containing details of a product from a product message being quoted or replied to using the 'Message Business' option.
Expand All @@ -298,11 +323,19 @@ public struct WhatsAppReferredProduct
/// <summary>
/// The ID of the catalog associated with the product from the product message being quoted or replied to using the 'Message Business' option.
/// </summary>
[JsonPropertyName("catalog_id")] public string CatalogId { get; set; }
[JsonPropertyName("catalog_id")]
public string CatalogId { get; set; }

/// <summary>
/// The ID of the product from the product message being quoted or replied to using the 'Message Business' option.
/// </summary>
[JsonPropertyName("product_retailer_id")]
public string ProductRetailerId { get; set; }
}
}

/// <summary>
/// </summary>
/// <param name="NetworkCode"></param>
public record Origin(
[property: JsonPropertyName("network_code")]
string NetworkCode);

0 comments on commit 02044e5

Please sign in to comment.