gabrieldwight / Whatsapp-Business-Cloud-Api-Net

This is C# wrapper of whatsapp business cloud api for .NET
MIT License
284 stars 104 forks source link

DocumentTemplateMessageRequest #13

Closed claudineibr closed 1 year ago

claudineibr commented 1 year ago

I didn't find the implementation for sending pdf documents, is this feature implemented?

gabrieldwight commented 1 year ago

Hi @claudineibr you will need to send the pdf documents using a media id or an external link. For using media Id, you will need to upload pdf document using **uploadMedia function which will return the media Id for your pdf document**.

I'm yet to test sending DocumentTemplateMessage using media Id. The implementation of the document template message was done to support pdf or any document file that is hosted by an external link that WhatsApp can use to retrieve the document file.

The approach to sending DocumentTemplateMessageRequest may be similar to ImageTemplateMessageRequest but it will depend on the number of parameters you have defined for your template message.

DocumentTemplateMessageRequest imageTemplateMessage = new DocumentTemplateMessageRequest();
                documentTemplateMessage.To = sendTemplateMessageViewModel.RecipientPhoneNumber;
                documentTemplateMessage.Template = new DocumentMessageTemplate();
                documentTemplateMessage.Template.Name = sendTemplateMessageViewModel.TemplateName;
                documentTemplateMessage.Template.Language = new DocumentMessageLanguage();
                documentTemplateMessage.Template.Language.Code = LanguageCode.English_US;
                documentTemplateMessage.Template.Components = new List<DocumentMessageComponent>()
                {
                    new DocumentMessageComponentt()
                    {
                        Type = "header",
                        Parameters = new List<DocumentMessageParameter>()
                        {
                            new DocumentMessageParameter()
                            {
                                Type = "document",
                                Document = new Document()
                                {
                                    Link = "<EXTERNAL_LINK_DOCUMENT>" // Link point where your document can be downloaded or retrieved by WhatsApp
                                }
                            }
                        },
                    },
                    new DocumentMessageComponent()
                    {
                        Type = "body",
                        Parameters = new List<DocumentMessageParameter>()
                        {
                            new DocumentMessageParameter()
                            {
                                Type = "text",
                                Text = "Order Invoice"
                            },
                        }
                    }
                }

Let me know if sending a document template message using an external link solves your issue.

claudineibr commented 1 year ago

Sorry, maybe my message wasn't clear, I did exactly like the example you gave, but the problem is that I couldn't find the interface to send DocumentTemplate like there is for image. see image I believe there should be a SendDocumentAttachmentTemplateMessageAsync

image

gabrieldwight commented 1 year ago

I can see the method is missing in the interface. I will add the implementation of SendDocumentAttachmentTemplateMessageAsync method today.

claudineibr commented 1 year ago

Thank you!

gabrieldwight commented 1 year ago

I have implemented the method. You can test it and let me know if it works on your side.

claudineibr commented 1 year ago

I have implemented the method. You can test it and let me know if it works on your side.

It worked out! Thanks! A question, can you inform the caption because the domento name is going empty WhatsApp Image 2022-09-15 at 10 48 08

gabrieldwight commented 1 year ago

I added an extra property for filename and caption for the document template message request. I guess specifying on the caption or filename should work,

claudineibr commented 1 year ago

I added an extra property for filename and caption for the document template message request. I guess specifying on the caption or filename should work,

ok, as soon as it's available I'll test and report the result. Thanks

gabrieldwight commented 1 year ago

Alright. The package update should be available as of now.

claudineibr commented 1 year ago

Alright. The package update should be available as of now.

When you pass the caption parameter, an error is thrown

image

Passing filename works, I think the caption can be removed

image

gabrieldwight commented 1 year ago

Thanks for the update. I think I will leave the caption property. They may add caption support for document template messages.