Vonage / vonage-dotnet-sdk

Vonage REST API client for .NET, written in C#. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
https://developer.vonage.com/
Apache License 2.0
107 stars 82 forks source link

Missing InboudMessage class for WhatsApp messages #298

Closed surexxx closed 1 year ago

surexxx commented 1 year ago

I'm started to using Messaging SDK and see that WhatsAppInboundMessage class is missing from SDK, that represents the inbound message structure got from webhook.

The JSON structure of message is descibed here: https://developer.vonage.com/api/messages-olympus?theme=dark#webhooks

Using the structure above a possible implementation is here:

using Vonage.Messages;

    public class WhatsAppInboundMessage
    {
        [JsonProperty("to")]
        public string To { get; set; }

        [JsonProperty("from")]
        public string From { get; set; }

        [JsonProperty("channel")]
        public MessagesChannel Channel { get; set; }

        [JsonProperty("message_uuid")]
        public string MessageUuid { get; set; }

        [JsonProperty("timestamp")]
        public DateTime Timestamp { get; set; }

        [JsonProperty("message_type")]
        public MessagesMessageType MessageType { get; set; }

        [JsonProperty("text")]
        public string Text { get; set; }

        [JsonProperty("profile")]
        public Profile Profile { get; set; }

        [JsonProperty("provider_message")]
        public string ProviderMessage { get; set; }

        [JsonProperty("context")]
        public Context Context { get; set; }

        [JsonProperty("client_ref")]
        public string ClientRef { get; set; }
    }

    public class Profile
    {
        [JsonProperty("name")]
        public string Name { get; set; }
    }

    public class Context
    {
        [JsonProperty("message_uuid")]
        public string MessageUuid { get; set; }

        [JsonProperty("message_from")]
        public string MessageFrom { get; set; }

        [JsonProperty("whatsapp_referred_product")]
        public WhatsAppReferredProduct WhatsAppReferredProduct { get; set; }
    }

    public class WhatsAppReferredProduct
    {
        [JsonProperty("catalog_id")]
        public string CatalogId { get; set; }

        [JsonProperty("product_retailer_id")]
        public string ProductRetailerId { get; set; }
    }

Please add it to your dotnet messaging sdk.

Tr00d commented 1 year ago

Hi @surexxx! Thanks for pointing this out and for your contribution. I added this item in my current sprint, so I can reasonably tell it will be done shortly. I'll share feedback regarding the progress. Have a great day!

Tr00d commented 1 year ago

@surexxx Just to clarify a bit, how would you use this class exactly? Deserializing JSON into WhatsAppInboundMessage? I'm asking because we don't provide any webhook-related features in the SDK.

surexxx commented 1 year ago

Yes, I'm using it to deserialize the WhatsApp JSON message:

image

You also provide a class like this in regard of receiving inbound SMS message:

image
Tr00d commented 1 year ago

Thanks for sharing. I just wanted to confirm my thoughts.

Tr00d commented 1 year ago

Hi @surexxx, Sorry for the delay. This one took longer than expected, as we had a lot of discussions about whether we should provide Webhooks classes in the SDK (or not). The class is now available under Messages/Webhooks, and supports all kind of messages (not just WhatsApp). You can look at the PR here #382. You'll have to update to v6.1.0 to use it.