Giter Site home page Giter Site logo

tinokrueger / waba360dialog.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yuenkik6/waba360dialog.net

0.0 0.0 0.0 171 KB

C# .NET API Wrapper Classes for 360Dialog WhatsApp Business APIs and Partner APIs

License: MIT License

C# 99.55% Dockerfile 0.45%

waba360dialog.net's Introduction

WABA360Dialog.NET

C# .NET API Wrapper Classes for 360Dialog WhatsApp Business APIs (On-Premises and Cloud API) and Partner APIs

  • 360Dialog WhatsApp Business API (On-Premises) Client
  • 360Dialog WhatsApp Business API (Cloud API) Client
  • 360Dialog WhatsApp Business API Sandbox Client
  • 360Dialog Partner API
  • Webhook Models

Getting Started

To get started, you must own an API Key managed by 360Dialog.

  • WABA360DialogApiClient.cs / WABA360DialogCloudApiClient.cs / WABA360DialogApiSandboxClient.cs (WhatsApp API Business API)
var client = new WABA360DialogApiClient("your-api-key");
var createMessageResposne = await client.SendMessageAsync(MessageObjectFactory.CreateTextMessage("whatsapp-id", "Hello World!"));
  • WABA360DialogPartnerClient.cs (360Dialog Partner API)
var partnerClient = new WABA360DialogPartnerClient(new PartnerInfo("partner-id"),"access-token"));
// or
var partnerClient = new WABA360DialogPartnerClient(new PartnerInfo("partner-id", "username", "password")); // For auto login

var clientBalanceResponse = await partnerClient.GetClientBalanceAsync("client-id", 1696118400, 1698796799, "month");

Available Functions

All existing API provided by 360 Dialog are wrapped as functions for corresponding client

  • WABA360DialogApiClient.cs / WABA360DialogApiSandboxClient.cs (WhatsApp API Business API (On-Premises))
Task<GetWebhookUrlResponse> GetWebhookUrlAsync(CancellationToken cancellationToken = default);
Task<SetWebhookUrlResponse> SetWebhookUrlAsync(string url, Dictionary<string, string> headers, CancellationToken cancellationToken = default);
Task<CheckContactsResponse> CheckContactsAsync(IEnumerable<string> contacts, Blocking blocking = Blocking.no_wait, bool forceCheck = false, CancellationToken cancellationToken = default);
Task<SendMessageResponse> SendMessageAsync(MessageObject message, CancellationToken cancellationToken = default);
Task<SendMessageResponse> SendMessageAsync(object message, CancellationToken cancellationToken = default);
Task<MarkMessagesAsReadResponse> MarkMessagesAsReadAsync(string messageId, CancellationToken cancellationToken = default);
Task<GetMediaResponse> GetMediaAsync(string mediaId, CancellationToken cancellationToken = default);
Task<UploadMediaResponse> UploadMediaAsync(byte[] fileBytes, string contentType, CancellationToken cancellationToken = default);
Task<GetTemplateResponse> GetTemplateAsync(int limit = 1000, int offset = 0, string sort = null, CancellationToken cancellationToken = default);
Task<CreateTemplateResponse> CreateTemplateAsync(CreateTemplateObject template, CancellationToken cancellationToken = default);
Task<DeleteTemplateResponse> DeleteTemplateAsync(string templateName, CancellationToken cancellationToken = default);
Task<UpdateBusinessProfileResponse> UpdateBusinessProfileAsync(IEnumerable<string> vertical, IEnumerable<string> websites, string email, string description, string address, CancellationToken cancellationToken = default);
Task<UpdateProfileInfoAboutTextResponse> UpdateProfileInfoAboutTextAsync(string aboutText, CancellationToken cancellationToken = default);
Task<UpdateProfileInfoPhotoResponse> UpdateProfileInfoPhotoAsync(byte[] fileBytes, string contentType, CancellationToken cancellationToken = default);
Task<CheckPhoneNumberResponse> CheckPhoneNumberAsync(CancellationToken cancellationToken = default);
Task<HealthCheckResponse> HealthCheckAsync(CancellationToken cancellationToken = default);
  • **WABA360DialogCloudApiClient.cs ** (WhatsApp API Business API (Cloud API))
Task<GetWebhookUrlResponse> GetWebhookUrlAsync(CancellationToken cancellationToken = default);
Task<SetWebhookUrlResponse> SetWebhookUrlAsync(string url, Dictionary<string, string> headers, CancellationToken cancellationToken = default);
Task<SendMessageResponse> SendMessageAsync(MessageObject message, CancellationToken cancellationToken = default);
Task<SendMessageResponse> SendMessageAsync(object message, CancellationToken cancellationToken = default);
Task<MarkMessagesAsReadResponse> MarkMessagesAsReadAsync(string messageId, CancellationToken cancellationToken = default);
Task<GetMediaInformationResponse> GetMediaInformationAsync(string mediaId, CancellationToken cancellationToken = default);
Task<GetMediaResponse> GetMediaAsync(string relativeUrl, CancellationToken cancellationToken = default);
Task<GetMediaResponse> GetMediaAsync(string relativeUrl, Dictionary<string, string> queryParams, CancellationToken cancellationToken = default);
Task<UploadMediaResponse> UploadMediaAsync(string fileName, byte[] fileBytes, string contentType, CancellationToken cancellationToken = default);
Task<GetTemplateResponse> GetTemplateAsync(int limit = 1000, int offset = 0, string sort = null, CancellationToken cancellationToken = default);
Task<CreateTemplateResponse> CreateTemplateAsync(CreateTemplateObject template, CancellationToken cancellationToken = default);
Task<DeleteTemplateResponse> DeleteTemplateAsync(string templateName, CancellationToken cancellationToken = default);
Task<UpdateBusinessProfileResponse> UpdateBusinessProfileAsync(IEnumerable<string> vertical, IEnumerable<string> websites, string email, string description, string address, CancellationToken cancellationToken = default);
  • WABA360DialogPartnerClient.cs (360Dialog Partner API)
Task<CreatePartnerWhatsAppBusinessApiTemplateResponse> CreatePartnerWhatsAppBusinessApiTemplateAsync(string whatsAppBusinessApiAccountId, string name, string category, WhatsAppLanguage language, TemplateComponentObject components, CancellationToken cancellationToken = default);
Task<GetClientBalanceResponse> GetClientBalanceAsync(string clientId, string clientId, long? startDate, long? endDate, string granularity, CancellationToken cancellationToken = default);
Task<GetPartnerChannelsResponse> GetPartnerChannelsAsync(int limit = 20, int offset = 0, string sort = null, GetPartnerChannelsFilter filters = null, CancellationToken cancellationToken = default);
Task<GetPartnerClientsResponse> GetPartnerClientsAsync(int limit = 20, int offset = 0, string sort = null, GetPartnerClientsFilter filters = null, CancellationToken cancellationToken = default);
Task<GetPartnerWebhookUrlResponse> GetPartnerWebhookUrlAsync(CancellationToken cancellationToken = default);
Task<SetPartnerWebhookUrlResponse> SetPartnerWebhookUrlAsync(string webhookUrl, CancellationToken cancellationToken = default);
Task<GetPartnerWhatsAppBusinessApiTemplatesResponse> GetPartnerWhatsAppBusinessApiTemplatesAsync(string whatsAppBusinessApiAccountId, int limit = 1000, int offset = 0, string sort = null, GetPartnerWhatsAppBusinessApiTemplatesFilter filters = null, CancellationToken cancellationToken = default);
Task<RemovePartnerWhatsAppBusinessApiTemplatesResponse> RemovePartnerWhatsAppBusinessApiTemplatesAsync(string whatsAppBusinessApiAccountId, string templateId, CancellationToken cancellationToken = default);
Task<SetCancellationRequestOnChannelResponse> SetCancellationRequestOnChannelAsync(string clientId, string channelId, bool enabled, CancellationToken cancellationToken = default);
Task<UpdateClientResponse> UpdateClientAsync(string clientId, string partnerPayload, CancellationToken cancellationToken = default);
Task<GetApiKeyByChannelResponse> GetApiKeyByChannelAsync(string clientId, CancellationToken cancellationToken = default);
Task<CreateApiKeyByChannelResponse> CreateApiKeyByChannelAsync(string clientId, CancellationToken cancellationToken = default);
Task<GetPartnerPublicDataResponse> GetPartnerPublicDataAsync(CancellationToken cancellationToken = default);
Task<PatchPartnerPublicDataResponse> PatchPartnerPublicDataAsync(string webhookUrl, string partnerRedirectUrl, CancellationToken cancellationToken = default);
Task<DeleteApiKeyByChannelResponse> DeleteApiKeyByChannelAsync(string clientId, CancellationToken cancellationToken = default);
Task<TokenResponse> RequestOAuthTokenAsync(string username, string password, CancellationToken cancellationToken = default);
  • All Response type now have Response Body field for recording http response body from 360Dialog public string ResponseBody { get; set; }

Helpers

  • MessageObjectFactory.cs is a simple factory for creating common MessageObject used in WABA360DialogApiClient.SendMessage()
MessageObjectFactory.CreateTextMessage(string whatsAppId, string textMessage, bool previewUrl = false);
MessageObjectFactory.CreateImageMessageByMediaId(string whatsAppId, string mediaId, string caption);
MessageObjectFactory.CreateImageMessageByLink(string whatsAppId, string imageLink, string caption, ProviderObject provider = null);
MessageObjectFactory.CreateVideoMessageByMediaId(string whatsAppId, string mediaId, string caption);
MessageObjectFactory.CreateVideoMessageByLink(string whatsAppId, string imageLink, string caption, ProviderObject provider = null);
MessageObjectFactory.CreateDocumentMessageByMediaId(string whatsAppId, string fileName, string mediaId, string caption);
MessageObjectFactory.CreateDocumentMessageByLink(string whatsAppId, string fileName, string documentLink, string caption, ProviderObject provider = null);
MessageObjectFactory.CreateAudioMessageByMediaId(string whatsAppId, string mediaId);
MessageObjectFactory.CreateAudioMessageByLink(string whatsAppId, string audioLink, ProviderObject provider = null);
MessageObjectFactory.CreateStickerMessageByMediaId(string whatsAppId, string mediaId);
MessageObjectFactory.CreateStickerMessageByLink(string whatsAppId, string stickerLink, ProviderObject provider = null);
MessageObjectFactory.CreateTemplateMessage(string whatsAppId, string templateNamespace, string templateName, WhatsAppLanguage language, List<ComponentObject> components);
MessageObjectFactory.CreateInteractiveMessage(string whatsappId, InteractiveObject interactiveObject);
MessageObjectFactory.CreateLocationMessage(string whatsappId, double latitude, double longitude, string name = null, string address = null);
MessageObjectFactory.CreateContactsMessage(string whatsappId, ContactObject contact);

Enums

The Enums definition, value, converters are located at these folders:

ApiClient\Payloads\Converters\...
ApiClient\Payloads\Enums\...

Cloud\ApiClient\Payloads\Enums

PartnerClient\Payloads\Converters\...
PartnerClient\Payloads\Enums\...

Common\Converters\...
Common\Enums\...
  • To Get the string value of the enums, use .GetString()

However, once Facebook updated the enums string value may cause issues during JSON deserialize.

Webhook Models

Webhook Models classes (Recommend using Newtonsoft.Json >= 13.01 for JSON deserialization):

  • WhatsApp API Business API (On-Premises)
ApiClient\Payloads\Models\WABA360DialogWebhookPayload.cs
  • WhatsApp API Business API (Cloud API)
Cloud\ApiClient\Payloads\Models\WebhookObjects\WebhookNotification.cs
  • 360Dialog Partner API
PartnerClient\Payloads\Models\WABA360DialogPartnerWebhookPayload.cs

Exceptions

Exceptions will throw when Response HTTP Status Code or Response is not success.

  • WhatsApp API Business API
ApiClientException // Throw when Response HTTP status code is not success, use ex.ToString() / ex.Error to access detail
  • 360Dialog Partner API
PartnerClientException  // Throw when HTTP Response Status Code is not success, use ex.ToString() / ex.Message to access detail
PartnerClientAuthenticationException // Throw when HTTP Response Status Code is 401 like access token invalid or no credentials set.

Example

Run WABA360Dialog.NET.Example with your Api Key and Partner Id, Token. It Include Swagger UI for you to test certain APIs.

You can either set the api key / partner secret through appsetting.json or Swagger UI

  1. appsetting.json Example:

    {
        "WABA360Dialog": {
            "ChannelApiKey": "",
            "PartnerId": "",
            "PartnerToken": ""
        }
    }
  2. Swagger UI > Authorize

    Set 360Dialog Channel ApiKey, Partner Id & Partner Token

Extendability

Feel free to extend or improve the capability of the current version of the client that cannot satisfy all your needs.

Please visit these Folder for more details:

ApiClient\Interfaces                            // Abstract WhatsApp Business API Client class
ApiClient\Payloads\Base                         // Abstract WhatsApp Business API Request & Response class
ApiClient\Payloads\                             // Concrete WhatsApp Business API Request & Response class

PartnerClient\Interfaces                        // Abstract Partner API Client class
PartnerClient\Payloads\Base                     // Abstract Partner API Request & Response class
PartnerClient\Payloads\                         // Concrete Partner API Request & Response class

Official Documents

waba360dialog.net's People

Contributors

sleekflowalexyuen avatar yuenkik6 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.