mtmsuhail /
ESC-POS-USB-NET
This project is a simple .NET (C#) Implementation of the Epson ESC/POS Printing using USB Device Driver.
Loading repository data…
gabrieldwight / repository
This is C# wrapper of whatsapp business cloud api for .NET
A Wrapper for the WhatsApp Business Cloud API hosted by Meta.
Official API Documentation: Meta for Developers
Sell Product and Services: Product Message Configuration
Account Metrics: Account Metrics Configuration for analytics and conversation analytics
QR Code Message Management: QR Code Messages for WhatsApp Business
WhatsApp Flows: Setting up WhatsApp Flows
WhatsApp Welcome Message: Setting up Conversational Components
WhatsApp Block User API: How to block a user
WhatsApp Cloud API Calling: How to set up cloud API VoIP calls
WhatsApp Group API: How to send messages to a group chat
Webhook Configuration Documentation: WhatsApp Cloud API Webhook
Authentication Message Documentation: Create and Send Authentication Message
WhatsApp Cloud API Error Codes: Error Codes
Take note: Sending a message to a phone number format 00[Country Code] xx xx xx using the prefix 00 before the country code will make the cloud API return an invalid parameter error (#100) (Credits @Tekkharibo)
Note: Downloading media from the generated WhatsApp media URL requires specifying the app name and version value as the user agent for the download media function to work. It is included as a property for the config class. (Credits @atmtrujillo)
Note: This package is WIP. The capabilities of the Cloud API will be reflected soon. Feel free to contribute!
Sending Messages
Receiving Message (via Webhook)
WhatsApp Business Management API
PM> Install-Package WhatsappBusiness.CloudApi> dotnet add package WhatsappBusiness.CloudApiBefore you proceed kindly acquaint yourself with WhatsApp Business Cloud Apis by going through the Docs in Meta's developer portal if you like.
Obtain a Temporary access token for the meta developers portal.
Ensure your project is running on the minimum supported versions of .Net
WhatsAppBusinessCloudAPi is dependency injection (DI) friendly and can be readily injected into your classes. You can read more on DI in Asp.Net core here. If you can't use DI you can always manually create a new instance of WhatsAppBusinessClient and pass in an httpClient instance in its constructor. eg.
// When Dependency Injection is not possible...
//create httpclient instance
var httpClient = new HttpClient();
httpClient.BaseAddress = WhatsAppBusinessRequestEndpoint.BaseAddress;
//create WhatsAppBusiness API client instance
var whatsAppBusinessClient = new WhatsAppBusinessClient(httpClient, whatsAppConfig); //make sure to pass httpclient and whatsAppConfig instance as an argument
I recommend creating WhatsAppBusinessClient using Dependency Injection. [Optional] You can use any IOC container or Microsoft DI container in your legacy projects.
// Adding Dependency Injection into legacy projects
public static IServiceProvider ServiceProvider;
// To be used in the main application startup method
void Application_Start(object sender, EventArgs e)
{
var hostBuilder = new HostBuilder();
hostBuilder.ConfigureServices(ConfigureServices);
var host = hostBuilder.Build();
ServiceProvider = host.Services;
}
void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient<IWhatsAppBusinessClient, WhatsAppBusinessClient>(options => options.BaseAddress = WhatsAppBusinessRequestEndpoint.BaseAddress);
//inject services here
}
using WhatsappBusiness.CloudApi.Configurations;
using WhatsappBusiness.CloudApi.Extensions;
WhatsAppBusinessCloudApiConfig whatsAppConfig = new WhatsAppBusinessCloudApiConfig();
whatsAppConfig.WhatsAppBusinessPhoneNumberId = builder.Configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessPhoneNumberId"];
whatsAppConfig.WhatsAppBusinessAccountId = builder.Configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessAccountId"];
whatsAppConfig.WhatsAppBusinessId = builder.Configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["WhatsAppBusinessId"];
whatsAppConfig.AccessToken = builder.Configuration.GetSection("WhatsAppBusinessCloudApiConfiguration")["AccessToken"];
builder.Services.AddWhatsAppBusinessCloudApiService(whatsAppConfig);
public class SendMessageController
{
private readonly IWhatsAppBusinessClient _whatsAppBusinessClient;
public SendMessageController(IWhatsAppBusinessClient whatsAppBusinessClient)
{
_whatsAppBusinessClient = whatsAppBusinessClient;
}
....
//code omitted for brevity
}
TextMessageRequest textMessageRequest = new TextMessageRequest();
textMessageRequest.To = "Recipient Phone Number";
textMessageRequest.Text = new WhatsAppText();
textMessageRequest.Text.Body = "Message Body";
textMessageRequest.Text.PreviewUrl = false;
var results = await _whatsAppBusinessClient.SendTextMessageAsync(textMessageRequest);
AudioMessageByUrlRequest audioMessage = new AudioMessageByUrlRequest();
audioMessage.To = "Recipient Phone Number";
audioMessage.Audio = new MediaAudioUrl();
audioMessage.Audio.Link = "Audio Url";
var results = await _whatsAppBusinessClient.SendAudioAttachmentMessageByUrlAsync(audioMessage);
DocumentMessageByUrlRequest documentMessage = new DocumentMessageByUrlRequest();
documentMessage.To = "Recipient Phone Number";
documentMessage.Document = new MediaDocumentUrl();
documentMessage.Document.Link = "Document Url";
var results = await _whatsAppBusinessClient.SendDocumentAttachmentMessageByUrlAsync(documentMessage);
ImageMessageByUrlRequest imageMessage = new ImageMessageByUrlRequest();
imageMessage.To = "Recipient Phone Number";
imageMessage.Image = new MediaImageUrl();
imageMessage.Image.Link = "Image Url";
var results = await _whatsAppBusinessClient.SendImageAttachmentMessageByUrlAsync(imageMessage);
StickerMessageByUrlRequest stickerMessage = new StickerMessageByUrlRequest();
stickerMessage.To = "Recipient Phone Number";
stickerMessage.Sticker = new MediaStickerUrl();
stickerMessage.Sticker.Link = "Sticker Url";
var results = await _whatsAppBusinessClient.SendStickerMessageByUrlAsync(stickerMessage);
VideoMessageByUrlRequest videoMessage = new VideoMessageByUrlRequest();
videoMessage.To = "Recipient Phone Number";
videoMessage.Video = new MediaVideoUrl();
videoMessage.Video.Link = "Video url";
var results = await _whatsAppBusinessClient.SendVideoAttachmentMessageByUrlAsync(videoMessage);
ContactMessageRequest contactMessageRequest = new ContactMessageRequest();
contactMessageRequest.To = "Recipient Phone Number";
contactMessageRequest.Contacts = new List<ContactData>()
{
new ContactData()
{
Addresses = new List<Address>()
{
new Address()
{
State = "State Test",
City = "City Test",
Zip = "Zip Test",
Country = "Country Test",
CountryCode = "Country Code Test",
Type = "Home"
}
},
Name = new Name()
{
FormattedName = "Testing name",
FirstName = "FName",
LastName = "LName",
MiddleName = "MName"
}
}
};
var results = await _whatsAppBusinessClient.SendContactAttachmentMessageAsync(contactMessageRequest);
LocationMessageRequest locationMessageRequest = new LocationMessageRequest();
locationMessageRequest.To = "Recipient Phone Number";
locationMessageRequest.Location = new Location();
locationMessageRequest.Location.Name = "Location Test";
locationMessageRequest.Location.Address = "Address Test";
locationMessageRequest.Location.Longitude = "location longitude";
locationMessageRequest.Location.Latitude = "location latitude";
var results = await _whatsAppBusinessClient.SendLocationMessageAsync(locationMessageRequest);
InteractiveListMessageRequest interactiveListMessage = new InteractiveListMessageRequest();
interactiveListMessage.To = "Recipient Phone Number";
interactiveListMessage.Interactive = new InteractiveListMessage();
interactiveListMessage.Interactive.Header = new Header();
interactiveListMessage.Interactive.Header.Type = "text";
interactiveListMessage.Interactive.Header.Text = "List Header Sample Test";
interactiveListMessage.Interactive.Body = new ListBody
Selected from shared topics, language and repository description—not editorial ratings.
mtmsuhail /
This project is a simple .NET (C#) Implementation of the Epson ESC/POS Printing using USB Device Driver.
edwardgushchin /
This is SDL3#, a C# wrapper for SDL3.
tghamm /
An unofficial C#/.NET SDK for accessing the Anthropic Claude API. This package is not affiliated with, endorsed by, or sponsored by Anthropic. Anthropic and Claude are trademarks of Anthropic, PBC.
Sample project
hez2010 /
This is a typedoc json to C# type bindings converter. Can be used as a TypeScript to C# bindings converter.
gehnster /
A C# library for accessing the EVE Online ESI API. This library is .NET Standard compatible.
Spinnernicholas /
This is a Visual Studio C# source generator for automatically generating enum extension methods that implement a switch expression based ToString method. Why? The default enum ToString method implements a binary search which is great for large lists but becomes time and memory inefficient for a just a few items when compared to a switch expression.