MetaBulkSDK V0.9 Beta


1. Getting Started With MetaBulkSDK

a) Getting an SDK Key

To get started with MetaBulkSDK, you'll need to obtain an SDK key from a supported marketplace like Techia.store ↗.

2. Installation

a) MetaBulkSDK

To use MetaBulkSDK in your C# project, download the DLL from Github and add it as a reference in your project.

b) Dependency Packages

MetaBulkSDK requires the following packages to be installed:

  1. CefSharp.OffScreen (preferred version: v114.2.120)
  2. Newtonsoft.Json (preferred version: v13.0.3)
  3. QRCoder (preferred version: v1.4.3)

Sure! Here's how you can install these packages via Package Manager:

NuGet\Install-Package CefSharp.OffScreen -Version 114.2.120
NuGet\Install-Package Newtonsoft.Json -Version 13.0.3
NuGet\Install-Package -Version 1.4.3

Sure, here's the rewritten markdown with additional comments:

3. Initializing the Client

To use the MetaBulkSDK library, you need to initialize the Client class with your SDK Key. Here's an example:

using MetaBulkSDK;

// Initialize the client with your SDK Key
Client client = new Client("SDK_Key");

4. Connection Status

The Client class provides access to the current connection status, which can be one of the following values:

  • notInitialized
  • offline
  • error
  • initializing
  • connecting
  • signing
  • notConnected
  • connected
  • working

You can handle connection status changes using the OnConnectionStatusChanged event:

// Subscribe to the OnConnectionStatusChanged event
client.OnConnectionStatusChanged += Client_OnConnectionStatusChanged;

// 4. Connection Status
private static void Client_OnConnectionStatusChanged(object sender, Client.Status e, string info)
{
    switch (e)
    {
        case Client.Status.notInitialized:
            break;
        case Client.Status.offline:
            Console.WriteLine("Client is offline");
            break;
        case Client.Status.error:
            Console.WriteLine("Client error: " + info);
            break;
        case Client.Status.initializing:
            Console.WriteLine("Initializing...");
            break;
        case Client.Status.connecting:
            Console.WriteLine("Connecting...");
            break;
        case Client.Status.signing:
            Console.WriteLine("Signing...");
            break;
        case Client.Status.notConnected:
            //Client is connected to WA API but doses not have a acount yet
            Console.WriteLine("Account not connected");
            break;
        case Client.Status.connected:
            // Here you can send a message, get account information, or start a campaign
            break;
        case Client.Status.working:
            Console.WriteLine("Client is working");
            break;
        default:
            break;
    }
}

5. OnQRChanged

The Client class has an event OnQRChanged that is triggered whenever the QR code changes. Here's an example:

// Subscribe to the OnQRChanged event
client.OnQRChanged += Client_OnQRChanged;

// OnQRChanged
private static void Client_OnQRChanged(object sender, QR qr)
{
    // Generate a Bitmap representation of the QR code
    Bitmap qrBitmap = qr.GenerateQrCode(Color.Black, Color.White);
}

6. OnMessageReceived

The Client class has an event OnMessageReceived that is triggered whenever a message is received. Here's an example:

// Subscribe to the OnMessageReceived event
client.OnMessageReceived += Client_OnMessageReceived;

// OnMessageReceived
private static void Client_OnMessageReceived(object sender, MetaBulkSDK.WA.Data.Message message)
{
    // Print the message details
    Console.WriteLine("\nMessage Received: \nSender Name: {0}\nSender Phone: {1}\nText: {2}\nMIME Type: {3}\n", message.Sender.Name, message.Sender.Phone, message.Text, message.Body.MIME);
}

7. Sending a Message

a) Sending a Message

You can send a simple text message to a contact using the SendMessage method. Here's an example:

// Phone Number Using international format ex:+1 408 XXX XXXX

// Send a simple text message
WorkDone result = client.SendMessage("Message Text", "Phone_Number");

// Check if the message was sent successfully
if (result.success)
{
    Console.WriteLine("Message sent successfully");
}
else
{
    Console.WriteLine("Failed to send message: " + result.msg);
}

b) Sending a File Message

You can send a message with a file attachment using the MessageTemplate class. Here's an example:

// Prepare the file to be attached
MessageTemplate.MessageTemplateFile templateFile = new MessageTemplate.MessageTemplateFile("_FilePath");

// Create a message template with the file attachment
MessageTemplate messageTemplate = new MessageTemplate("MessageTemplateName", "Hello John Smith, how are you?", templateFile);

// Send the message with the file attachment
WorkDone result = client.SendMessage(messageTemplate, contact);

// Check if the message was sent successfully
if (result.success)
{
    Console.WriteLine("Message sent successfully");
}
else
{
    Console.WriteLine("Failed to send message: " + result.msg);
}

c) Sending a Buttons Message

You can send a message with buttons using the MessageTemplate class. Here's an example:

// Prepare the buttons to be included in the message
List<MessageTemplate.MessageTemplateButton> templateButtons = new List<MessageTemplate.MessageTemplateButton>();

// Add a URL button
templateButtons.Add(new MessageTemplate.MessageTemplateButton(MessageTemplate.MessageTemplateButton.ButtonTypes.url, @"https://_Url/", "Button Title"));

// Add a phone button
templateButtons.Add(new MessageTemplate.MessageTemplateButton(MessageTemplate.MessageTemplateButton.ButtonTypes.phoneNumber, @"+xxxxxxxxxxx", "Button Title"));

// Add a reply button
templateButtons.Add(new MessageTemplate.MessageTemplateButton(MessageTemplate.MessageTemplateButton.ButtonTypes.id, "id", "Button Title"));

// Create a message template with the buttons
MessageTemplate messageTemplate = new MessageTemplate("MessageTemplateName", "Hello John Smith, how are you?", null, templateButtons);

// Send the message with the buttons
WorkDone result = client.SendMessage(messageTemplate, contact);

8. Creating a Campaign

To create a new campaign, you need to prepare your audience, message template, and campaign settings. Here are the steps to create a new campaign:

a) Prepare your audience

To prepare your audience, you can create a new audience book and add contacts to it. Here's an example:

List<Contact> contacts = new List<Contact>();
contacts.Add(new Contact("John Smith 1", "Phone_Number", ""));
contacts.Add(new Contact("John Smith 2", "Phone_Number", ""));
AudienceBook audienceBook = new AudienceBook("Audience 1", contacts);

In this example, a new audience book object is created with the name "Audience 1" and two contacts, "John Smith 1" and "John Smith 2".

b) Prepare your message template

To prepare your message template, you can create a new message template object. Here's an example:

MessageTemplate messageTemplate = new MessageTemplate("MessageTemplateName", "Hello John Smith, how are you?");

In this example, a new message template object is created with the name "MessageTemplateName" and the content "Hello John Smith, how are you?".

c) Prepare your campaign

To prepare your campaign, you can create a new campaign object and set its properties. Here's an example:

Campaign campaign = new Campaign();
campaign.Name = "Test Campaign";
campaign.SelectedAudience = audienceBook;
campaign.SelectedTemplate = messageTemplate;

In this example, a new campaign object is created with the name "Test Campaign", the selected audience book "Audience 1", and the selected message template "MessageTemplateName".

You can also set additional campaign settings using the CampaignConfiguration class. For example, you can set the maximum number of messages per send request or the delay between send requests. Here's an example:

CampaignConfiguration configuration = new CampaignConfiguration();
configuration.MaxMessagesPerSendRequest = 100;
configuration.DelayBetweenSendRequests = TimeSpan.FromSeconds(10);
campaign.Configuration = configuration;

In this example, a new campaign configuration object is created with the maximum number of messages per send request set to 100 and the delay between send requests set to 10 seconds. The campaign configuration object is then assigned to the Configuration property of the campaign object.

d) Set CampaignWorker event

To run the campaign, you need to set up the CampaignWorker event handler. The CampaignWorker class is responsible for sending messages to the audience. You can use the OnProgressUpdated event of the CampaignWorker class to monitor the progress of the campaign. Here's an example:

client.CampaignWorker.OnProgressUpdated += CampaignWorker_OnProgressUpdated;

In this example, the OnProgressUpdated event of the CampaignWorker class is set to the CampaignWorker_OnProgressUpdated method.

e) Run Campaign

To run the campaign, you can call the RunCampaign method of the CampaignWorker class. Here's an example:

client.CampaignWorker.RunCampaign(campaign);

In this example, the RunCampaign method of the CampaignWorker class is called with the campaign object as a parameter.

f) Using CampaignWorker OnProgressUpdated

using To monitor the progress of the campaign, you can use the OnProgressUpdated event of the CampaignWorker class. Here's an example:

private static void CampaignWorker_OnProgressUpdated(object sender, CampaignProgressEventArgs e)
{
    Console.WriteLine($"Sent: {e.SuccessfulCount}, Failed: {e.FailedCount}, Remaining: {e.RemainingCount}");
}

In this example, the CampaignWorker_OnProgressUpdated method is called whenever the OnProgressUpdated event of the CampaignWorker class is triggered. The method prints the number of successful and failed messages and the number of remaining messages to be sent.

Example

Here's an example of how to create and run a new campaign:

// Prepare your audience
List<Contact> contacts = new List<Contact>();
contacts.Add(new Contact("John Smith 1", "Phone_Number", ""));
contacts.Add(new Contact("John Smith 2", "Phone_Number", ""));
AudienceBook audienceBook = new AudienceBook("Audience 1", contacts);

// Prepare your message template
MessageTemplate messageTemplate = new MessageTemplate("MessageTemplateName", "Hello John Smith, how are you?");

// Prepare your campaign
Campaign campaign = new Campaign();
campaign.Name = "Test Campaign";
campaign.SelectedAudience = audienceBook;
campaign.SelectedTemplate = messageTemplate;

// Set campaign configuration
CampaignConfiguration configuration = new CampaignConfiguration();
configuration.MaxMessagesPerSendRequest = 100;
configuration.DelayBetweenSendRequests = TimeSpan.FromSeconds(10);
campaign.Configuration = configuration// Set CampaignWorker event
client.CampaignWorker.OnProgressUpdated += CampaignWorker_OnProgressUpdated;

// Run Campaign
client.CampaignWorker.RunCampaign(campaign);

// CampaignWorker_OnProgressUpdated method
private static void CampaignWorker_OnProgressUpdated(object sender, CampaignProgressEventArgs e)
{
    Console.WriteLine($"Sent: {e.SuccessfulCount}, Failed: {e.FailedCount}, Remaining: {e.RemainingCount}");
}

In this example, a new campaign is created with the name "Test Campaign", the selected audience book "Audience 1", and the selected message template "MessageTemplateName". The campaign configuration is also set with a maximum of 100 messages per send request and a delay of 10 seconds between send requests.

The CampaignWorker event handler is set to the CampaignWorker_OnProgressUpdated method, which prints the progress of the campaign to the console.

Finally, the campaign is run using the RunCampaign method of the CampaignWorker class.

9. Using Data Management

MetaBulkSDK provides three managers for data management; AudienceManager, MessageTemplatesManager, and CampaigainHistory.

a) AudienceManager

The AudienceManager class is responsible for managing audience books. You can use the following methods to manage audience books:

//Create Audience
AudienceBook audienceBook = new AudienceBook("audienceBook_name", new List<Contact>());

//Add Contact
audienceBook.AddContact(new Contact("John Smith 1", "Phone_Number", ""));

//Get Contact
Contact getContact = audienceBook.GetContactByPhone("Phone_Number");

//Add audienceBook
client.AudienceManager.AddBook(audienceBook);

//Retrieve audienceBook
AudienceBook audienceBook1 = client.AudienceManager.GetBook("audienceBook_name");

//Delete audienceBook
client.AudienceManager.RemoveBookByName("audienceBook_name");

//Export Data
client.AudienceManager.Export("file_path");

//Import from Data
client.AudienceManager.Import("file_path");

//Events
client.AudienceManager.OnDataChanged += AudienceManager_OnDataChanged;

b) MessageTemplatesManager

The MessageTemplatesManager class is responsible for managing message templates. You can use the following methods to manage message templates:

//Add Template
client.MessageTemplatesManager.AddTemplate(new MessageTemplate("MessageTemplateName", "Hello John Smith, how are you?"));

//Retrieve Template
MessageTemplate messageTemplate = client.MessageTemplatesManager.GetTemplate("MessageTemplateName");

//Delete Template
client.MessageTemplatesManager.RemoveTemplate("MessageTemplateName");

//Export Data
client.MessageTemplatesManager.Export("file_path");

//Import from Data
client.MessageTemplatesManager.Import("file_path");

//Events
client.MessageTemplatesManager.OnDataChanged += MessageTemplatesManager_OnDataChanged;

c) CampaignHistoryManager

The CampaigainHistoryManager class is responsible for managing campaign results. You can use the following methods to manage campaign results:

//Add Results
client.CampaigainHistory.AddResults(new CampaignResult());

//Retrieve Results
CampaignResult messageTemplate = client.CampaigainHistory.GetResults("MessageTemplateName");

//Statistics
int ResultsCount = client.CampaigainHistory.ResultsCount;
int TotalRecordsCount = client.CampaigainHistory.TotalRecordsCount();
int TotalSuccessRecordsCount = client.CampaigainHistory.TotalSuccessRecordsCount();
int TotalFailedRecordsCount = client.CampaigainHistory.TotalFailedRecordsCount();

//Export Data
client.CampaigainHistory.Export("file_path");

//Import from Data
client.CampaigainHistory.Import("file_path");

//Events
client.CampaigainHistory.OnDataChanged += MessageTemplatesManager_OnDataChanged;

By using these managers, you can easily manage your audience, message templates, and campaign results. You can export and import data from local files and subscribe to events to get notified of any changes.

Sure! Here's a more detailed version of the logout section:

10. Logging out

When you're finished using a client object, it's important to log out to release any resources and connections that were used. To log out from the client, you can call the Logout method of the client object. Here's an example:

bool success = client.Logout();
if (success)
{
    Console.WriteLine("Logout successful.");
}

In this example, the Logout method of the client object is called, and the return value is stored in the success variable. If the logout is successful, the message "Logout successful." is printed to the console.

Disposing the client

In addition to logging out, you should also dispose of the client object when you're finished using it. This ensures that any resources used by the client are released. To dispose of the client, you can call the Dispose method of the client object. Here's an example:

client.Dispose();

In this example, the Dispose method of the client object is called to release any resources used by the client.

Example

Here's an example of how to log out and dispose of the client object:

// Log out the client
bool success = client.Logout();
if (success)
{
    Console.WriteLine("Logout successful.");
}

// Dispose of the client
client.Dispose();

In this example, the Logout method of the client object is called to log out, and the Dispose method of the client object is called to release any resources used by the client. If the logout is successful, the message "Logout successful." is printed to the console.

MetaBulkSDK Documentation V0.9 Beta

MetaBulkSDK Namespace

The MetaBulkSDK namespace contains classes used throughout the library.

MetaBulkSDKException Class

The MetaBulkSDKException class is used to represent exceptions thrown by the MetaBulkSDK library. It inherits from the System.Exception class.

Constructors

  • MetaBulkSDKException(string message) - Initializes a new instance of the MetaBulkSDKException class with a specified error message.
  • MetaBulkSDKException(string source, string code, string message = null) - Initializes a new instance of the MetaBulkSDKException class with a specified error source, error code, and optional error message.

Properties

  • Code - Gets or sets the error code associated with the exception.

Example


    try
    {
        // code that may throw an exception
    }
    catch (MetaBulkSDKException ex)
    {
        Console.WriteLine($Error code: {ex.Code}, Message: {ex.Message});
    }
    

Configuration Class

The Configuration class is used to store global configuration settings for the MetaBulkSDK library.

Properties

  • FileLimit - Gets or sets the maximum file size limit for messages.
  • UserDataPath - Gets or sets the path to the user data directory.

Example


    // Set the maximum file size limit for messages
    Configuration.FileLimit = 10000000;
    
    // Set the path to the user data directory
    Configuration.UserDataPath = @C:\Users\JohnDoe\AppData\Roaming\MetaBulkSDK\userData\profiles;
    

WorkDone Class

The WorkDone class is used as a container for the return values of asynchronous methods across the MetaBulkSDK library.

Properties

  • sucsses (bool): A boolean representing whether the operation was successful.
  • msg (string): A message describing the result of the operation.
  • returnData (object): The data returned by the operation.
  • returnDataType (Type): The type of the data returned by the operation.

Constructors

  • WorkDone(bool sucsses, string msg, object returnData, Type returnDataType = null): Initializes a new instance of the WorkDone class with the specified properties.

MetaBulkSDK.Data Namespace

The MetaBulkSDK.Data namespace contains classes used to represent data objects used throughout the library.

SimpleContact Class

The SimpleContact class is used to represent a simple contact with basic contact information.

Properties

  • Name - Gets or sets the name of the contact.
  • AlternativeName - Gets or sets an alternative name for the contact.
  • Phone - Gets or sets the phone number of the contact.
  • Email - Gets or sets the email address of the contact.
  • FacebookURL - Gets or sets the Facebook profile URL of the contact.
  • TelegramUsernames - Gets or sets the Telegram usernames of the contact.

Constructors

  • SimpleContact() - Initializes a new instance of the SimpleContact class with default values.
  • SimpleContact(string name, string phone) - Initializes a new instance of the SimpleContact class with the specified name and phone number.
  • SimpleContact(string name, string phone, string alternativeName = , string email = , string facebookURL = , string telegramUsernames = ) - Initializes a new instance of the SimpleContact class with the specified name, phone number, and optional additional contact information.

Example


    // Create a new instance of the SimpleContact class
    var contact = new SimpleContact(John Doe, 1234567890);
    
    // Set additional contact information
    contact.Email = johndoe@example.com;
    contact.FacebookURL = https://www.facebook.com/johndoe;
    

SimpleGroup Class

The SimpleGroup class is used to represent a simple group with basic group information.

Properties

  • name - Gets or sets the name of the group.
  • id - Gets or sets the ID of the group.

Constructors

  • SimpleGroup() - Initializes a new instance of the SimpleGroup class with default values.
  • SimpleGroup(string name = , string id = ) - Initializes a new instance of the SimpleGroup class with the specified name and ID.

Example


    // Create a new instance of the SimpleGroup class
    var group = new SimpleGroup(My Group, 123456);
    
    // Change the group name
    group.name = New Name;
    

GroupBook Class

The GroupBook class is used to represent a collection of groups.

Properties

  • groupsList - Gets or sets a list of SimpleGroup objects contained in the group book.
  • name - Gets or sets the name of the group book.
  • creation - Gets or sets the creation date of the group book.

Constructors

  • GroupBook() - Initializes a new instance of the GroupBook class with default values.
  • GroupBook(string name, List<SimpleGroup> groupsList) - Initializes a new instance of the GroupBook class with the specified name and list of groups.

Methods

  • addGroup(SimpleGroup group) - Adds a new SimpleGroup object to the groupsList.

Example


    // Create a new instance of the GroupBook class
    var groupBook = new GroupBook(My Group Book, new List<SimpleGroup>());
    
    // Add a new group to the group book
    var newGroup = new SimpleGroup(New Group, 654321);
    groupBook.addGroup(newGroup);
    

MetaBulkSDK.Licensing Namespace

The MetaBulkSDK.Licensing namespace contains classes and methods used for licensing the MetaBulkSDK library.

LicenseInfo Class

The LicenseInfo class is used to represent license information for the MetaBulkSDK library.

Properties

  • Message - Gets a message associated with the license.
  • LoginMethod - Gets the login method used to activate the license. Possible values are SDKKey, ActivationKey, or Account.
  • ProductKey - Gets the product key associated with the license.
  • ActivationKey - Gets the activation key associated with the license.
  • IsVaild - Gets a boolean value indicating whether the license is valid.
  • ExpiredDate - Gets the expiration date of the license.
  • Quota - Gets the quota associated with the license.
  • SDKKey - Gets the SDK key associated with the license.
  • UserEmail - Gets the email address associated with the license.
  • UserPass - Gets the password associated with the license.
  • UserToken - Gets the user token associated with the license.
  • UserName - Gets the username associated with the license.

MetaBulkSDK.WA.Data Namespace

The MetaBulkSDK.WA.Data namespace contains classes used for representing data related to the WhatsApp messaging service.

Message Class

The Message class is used to represent a message in WhatsApp.

Properties

  • ChatType - Gets the type of chat associated with the message. Possible values are groupChat or userChat.
  • Chat - Gets or sets the chat associated with the message.
  • ID - Gets or sets the ID of the message.
  • ReferenceMessageID - Gets or sets the ID of the referenced message.
  • Self - Gets or sets a boolean value indicating whether the message was sent by the user.
  • Sender - Gets or sets the contact who sent the message.
  • Type - Gets or sets the type of message. Possible values are chat, file, action, sticker, or poll_creation.
  • Text - Gets or sets the text content of the message.
  • Body - Gets or sets the body of the message.
  • Time - Gets or sets the time the message was sent.

Constructors

  • Message(): Initializes a new instance of the Message class.
  • Message(string chatType, Chat chat, string id, string referenceMessageID, bool self, Contact sender, string type, string text, MessageBody body, DateTime time): Initializes a new instance of the Message class with the specified properties.

MessageBody Class

The MessageBody class is used to represent the body of a message in WhatsApp.

Constructors

  • MessageBody(): Initializes a new instance of the MessageBody class.
  • MessageBody(string text, string caption, MessageTemplate template, MessageTemplateFile file, List<MessageTemplateButton> buttons): Initializes a new instance of the MessageBody class with the specified properties.

BodyExtensions Class

The BodyExtensions class contains extension methods for the MessageBody class.

Group Class

The Group class is used to represent a group chat in WhatsApp.

Properties

  • Name - Gets or sets the name of the group.
  • ID - Gets or sets the ID of the group.

Constructors

  • Group(): Initializes a new instance of the Group class.
  • Group(string name, string id): Initializes a new instance of the Group class with the specified properties.

Contact Class

The Contact class is used to represent a contact in WhatsApp.

Properties

  • WaID - Gets the ID of the contact in WhatsApp.

Constructors

  • Contact(): Initializes a new instance of the Contact class.
  • Contact(string waID): Initializes a new instance of the Contact class with the specified WaID.

Example


    // Create a new instance of the Contact class
    var contact = new Contact();
    
    // Get the name of the contact
    var name = contact.Name;
    

MessageTemplate Class

The MessageTemplate class is used to represent a message template in WhatsApp.

Properties

  • Name - Gets or sets the name of the message template.
  • Text - Gets or sets the text content of the message template.
  • Creation - Gets or sets the creation date of the message template.
  • Title - Gets or sets the title of the message template.
  • Footer - Gets or sets the footer of the message template.
  • File - Gets or sets the file associated with the message template.
  • Buttons - Gets or sets the buttons associated with the message template.

Constructors

  • MessageTemplate(): Initializes a new instance of the MessageTemplate class.
  • MessageTemplate(string name, string text, DateTime creation, string title, string footer, MessageTemplateFile file, List<MessageTemplateButton> buttons): Initializes a new instance of the MessageTemplate class with the specified properties.

MessageTemplateButton Class

The MessageTemplateButton class is used to represent a button in a message template in WhatsApp.

Constructors

  • MessageTemplateButton(): Initializes a new instance of the MessageTemplateButton class.
  • MessageTemplateButton(string text, string url): Initializes a new instance of the MessageTemplateButton class with the specified text and url.

MessageTemplateFile Class

The MessageTemplateFile class is used to represent a file in a message template in WhatsApp.

Constructors

  • MessageTemplateFile(): Initializes a new instance of the MessageTemplateFile class.
  • MessageTemplateFile(string name, string url): Initializes a new instance of the MessageTemplateFile class with the specified nameand url.

QR Class

The QR class is used to represent a QR code in WhatsApp.

Properties

  • Code - Gets the code associated with the QR code.

Constructors

  • QR(): Initializes a new instance of the QR class.
  • QR(string code): Initializes a new instance of the QR class with the specified code.

Example


    // Create a new instance of the QR class
    var qr = new QR();
    
    // Get the code associated with the QR code
    var code = qr.Code;
    

Chat Class

The Chat class is used to represent a chat in WhatsApp.

Properties

  • Messages - Gets or sets the messages associated with the chat.
  • chatWith - Gets or sets the contact associated with the chat.

Constructors

  • Chat(): Initializes a new instance of the Chat class.
  • Chat(List<Message> messages, Contact chatWith): Initializes a new instance of the Chat class with the specified properties.

Campaign Class

The Campaign class is used to represent a campaign in WhatsApp.

Properties

  • Name - Gets or sets the name of the campaign.
  • SelectedTemplate - Gets or sets the message template selected for the campaign.
  • SelectedAudience - Gets or sets the audience selected for the campaign.
  • SelectedGroup - Gets or sets the group selected for the campaign.
  • Configuration - Gets or sets the configuration for the campaign.

Constructors

  • Campaign(): Initializes a new instance of the Campaign class.
  • Campaign(string name, MessageTemplate selectedTemplate, Audience selectedAudience, Group selectedGroup, CampaignConfiguration configuration): Initializes a new instance of the Campaign class with the specified properties.

CampaignConfiguration Class

The CampaignConfiguration class is used to represent the configuration for a campaign in WhatsApp.

Properties

  • DelayAfterXMessages - Gets or sets the delay after X messages for the campaign.
  • DelayAfterEveryMessages - Gets or sets the delay after every X messages for the campaign.
  • MaxRandomDelay - Gets or sets the maximum random delay for the campaign.
  • AppliedNumOfMessages - Gets or sets the number of messages applied for the campaign.

Constructors

  • CampaignConfiguration(): Initializes a new instance of the CampaignConfiguration class.
  • CampaignConfiguration(int delayAfterXMessages, int delayAfterEveryMessages, int maxRandomDelay, int appliedNumOfMessages): Initializes a new instance of the CampaignConfiguration class with the specified properties.

CampaignResult Class

The CampaignResult class is used to represent the result of a campaign in WhatsApp.

Properties

  • Name - Gets or sets the name of the campaign.
  • AccountPhone - Gets or sets the phone associated with the account.
  • status - Gets or sets the status of the campaign.
  • StartDate -Gets or sets the start date of the campaign.
  • EndDate - Gets or sets the end date of the campaign.
  • TotalMessagesSent - Gets or sets the total number of messages sent for the campaign.
  • SuccessfulMessagesSent - Gets or sets the number of successful messages sent for the campaign.
  • FailedMessagesSent - Gets or sets the number of failed messages sent for the campaign.
  • DeliveryRate - Gets or sets the delivery rate of the campaign.
  • ReadRate - Gets or sets the read rate of the campaign.

Constructors

  • CampaignResult(): Initializes a new instance of the CampaignResult class.
  • CampaignResult(string name, string accountPhone, string status, DateTime startDate, DateTime endDate, int totalMessagesSent, int successfulMessagesSent, int failedMessagesSent, double deliveryRate, double readRate): Initializes a new instance of the CampaignResult class with the specified properties.

MetaBulkSDK.WA Namespace

The The MetaBulkSDK.WA contains classes used for representing data related to the WhatsApp messaging service.

Client Class

The client class is used to represent exceptions thrown by the MetaBulkSDK library. It inherits from the System.Exception class.

Constructors

Client(string SDKKey, string ProfileID = wau)

Initializes a new instance of the Client class with the specified SDK key and profile ID.

public Client(string SDKKey, string ProfileID = wau)
    

Parameters:

  • SDKKey: The SDK key to use for authentication.
  • ProfileID: The ID of the profile to use. Default is wau.

Properties

OnConnectionStatusChanged

An event that is triggered when the connection status of the client changes. The event handler should have the following signature:

void OnConnectionStatusChanged(object sender, Status e, string info)
    

Where:

  • sender: The object that raised the event (the Client object).
  • e: The new status of the connection.
  • info: Additional information about the connection status change.

OnMessageReceived

An event that is triggered when a new message is received by the client. The event handler should have the following signature:

void OnMessageReceived(object sender, Message message)
    

Where:

  • sender: The object that raised the event (the Client object).
  • message: The message that was received.

OnQRChanged

An event that is triggered when a new QR code is generated by the client. The event handler should have the following signature:

void OnQRChanged(object sender, QR qr)
    

Where:

  • sender: The object that raised the event (the Client object).
  • qr: The new QR code.

LicenseInfo

Gets the license information for the client.

public LicenseInfo LicenseInfo { get; private set; }
    

CampaignWorker

Gets the campaign worker for the client.

public CampaignWorker CampaignWorker { get; private set; }
    

MessageTemplatesManager

Gets or sets the message templates manager for the client.

public MessageTemplatesManager MessageTemplatesManager { get; set; }
    

AudienceManager

Gets or sets the audience manager for the client.

public AudienceManager AudienceManager { get; set; }
    

CampaigainHistory

Gets or sets the campaign results manager for the client.

public CampaignResultsManager CampaigainHistory { get; set; }
    

connectionStatus

Gets the current connection status of the client.

public Status connectionStatus { get; private set; } = Status.notInitialized;
    

AccountID

Gets or sets the account ID for the client.

public string AccountID { get; set; } = Unknown;
    

Example:

Client client = new Client(my-sdk-key);
    

Client(string userEmail, string userPassword, string ProfileID = wau)

Initializes a new instance of the Client class with the specified user email, password, and profile ID.

public Client(string userEmail, string userPassword, string ProfileID = wau)
    

Parameters:

  • userEmail: The email address of the user to use for authentication.
  • userPassword: The password of the user to use for authentication.
  • ProfileID: The ID of the profile to use. Default is wau.

Example:

Client client = new Client(my-email@example.com, my-password);
    

Client(KeyPair activationKey, string ProfileID = wau)

Initializes a new instance of the Client class with the specified activation key and profile ID.

public Client(KeyPair activationKey, string ProfileID = wau)
    

Parameters:

  • activationKey: The activation key to use for authentication.
  • ProfileID: The ID of the profile to use. Default is wau.

Example:

KeyPair keyPair = new KeyPair(my-product-key, my-activation-key);
    Client client = new Client(keyPair);
    

Methods

IsShutdown

Gets whether the CEF framework used by the client is shutdown.

public static bool IsShutdown { get { return Cef.IsShutdown; } }
    

Example:

bool isShutdown = Client.IsShutdown;
    

GetProductKey

Gets the product key for the client.

public static string GetProductKey(){}
    

Example:

string productKey = Client.GetProductKey();
    

CheckLicense

Checks the license information for the client using the specified activation key, SDK key, user email, or user password.

public static async Task<LicenseInfo> CheckLicense(string activationKey = , string sdkKey = ,string userEmail = , string userPassword = )
    

Parameters:

  • activationKey: The activation key to use for authentication.
  • sdkKey: The SDK key to use for authentication.
  • userEmail: The email address of the user to use for authentication.
  • userPassword: The password of the user to use for authentication.

Returns:

  • A Task containing the license information for the client.

Example:

LicenseInfo licenseInfo = await Client.CheckLicense(sdkKey: my-sdk-key);
    

RevokeLicense

Revokes the license for the specified license information.

public static async Task RevokeLicense(LicenseInfo licenseInfo)
    

Parameters:

  • licenseInfo: The license information to revoke.

Example:

LicenseInfo licenseInfo = await Client.CheckLicense(sdkKey: my-sdk-key);
    await Client.RevokeLicense(licenseInfo);
    

DeleteProfile

Deletes the profile data for the client.

public static void DeleteProfile(){}
    

Example:

Client.DeleteProfile();
    

DeleteProfileSafe

Deletes the profile data for the client safely.

public static void DeleteProfileSafe(){}
    

Example:

Client.DeleteProfileSafe();
    

Connect

Connects the client to WhatsApp.

public async Task Connect()
    

Example:

await client.Connect();
    

RefreshQR

Refreshes the QR code used for authentication with WhatsApp.

public async Task RefreshQR()
    

Example:

await client.RefreshQR();
    

SendMessage

Sends a message to the specified contact using the specified message template or text message.

public async Task<Message> SendMessage(string contactNumber, string message, string messageId = null, 
        string templateName = null, Dictionary<string, string> placeholders = null)
    

Parameters:

  • contactNumber: The phone number of the contact to send the message to.
  • message: The text of the message to send.
  • messageId: The ID of the message to send. If not specified, a new ID will be generated.
  • templateName: The name of the message template to use. If not specified, the message will be sent as a regular text message.
  • placeholders: A dictionary of placeholders and their corresponding values to replace in the message template.

Returns:

  • A Task containing the message that was sent.

Example:

Message message = await client.SendMessage(+1234567890, Hello, world!);
    

GetAccountInfo

Retrieves the account information for the client.

public async Task<Profile> GetAccountInfo()
    

Returns:

  • A Task containing the account information for the client.

Example:

Profile accountInfo = await client.GetAccountInfo();
    

GetAccountInfoSafe

Retrieves the account information for the client safely.

public async Task<Profile> GetAccountInfoSafe()
    

Returns:

  • A Task containing the account information for the client.

Example:

Profile accountInfo = await client.GetAccountInfoSafe();
    

GetChat

Retrieves the chat with the specified ID, contact, or group.

public async Task<Chat> GetChat(string id)
    

Parameters:

  • id: The ID of the chat to retrieve.

Returns:

  • A Task containing the chat with the specified ID.

Example:

Chat chat = await client.GetChat(1234567890-1612345678@g.us);
    

GetChatAsync

Retrieves the chat with the specified ID, contact, or group asynchronously.

public async Task<Chat> GetChatAsync(string id)
    

Parameters:

  • id: The ID of the chat to retrieve.

Returns:

  • A Task containing the chat with the specified ID.

Example:

Chat chat = await client.GetChatAsync(1234567890-1612345678@g.us);
    

Logout

Logs out the client from WhatsApp.

public async Task Logout()
    

Example:

await client.Logout();
    

Dispose

Disposes of the client object and releases any resources used by it.

public void Dispose()
    

Example:

client.Dispose();
    

Shutdown

Shuts down the CEF framework used by the client.

public static void Shutdown()
    

Example:

Client.Shutdown();
    

Usage Examples

Connecting to WhatsApp

To connect to WhatsApp using the Client class, you first need to create a new instance of the class and provide it with the necessary authentication information (e.g., SDK key, user email and password, or activation key).