Coder Social home page Coder Social logo

thjli / whatsapphelper Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 15 KB

Utility library crafted to streamline interactions with the WhatsApp Business API for developers using C# and .NET Core

C# 100.00%
whatsapp cloud-api hook automation chatbot conversation dotnetcore whatsapp-business-api

whatsapphelper's Introduction

WhatsAppHelper for C# .NET Core Developers

WhatsAppHelper is a utility library designed to simplify interactions with the WhatsApp Business API. It provides a set of functionalities that allow developers to send and receive messages, manage contacts, and handle various aspects of WhatsApp communication within their .NET Core applications.

Features

  • Send templated messages to WhatsApp contacts.
  • Send text messages to WhatsApp contacts.
  • Receive and process incoming WhatsApp messages.
  • Manage authentication and token renewal for WhatsApp Business API.
  • Handle various aspects of WhatsApp communication.

Installation

You can install the WhatsAppHelper library using NuGet Package Manager:

dotnet add package WhatsAppHelper

Setting Up Services

In your Startup.cs file, configure the necessary services:

using WhatsAppHelper.Extensions;
// ...
public void ConfigureServices(IServiceCollection services)
{
    services.AddHttpClient();
    services.AddWaHelper();
}

Sending Templated Messages

using WhatsAppHelper.Models;
using WhatsAppHelper.Components;

// ...
var config = GetConfig();
var waConfig = new WaConfig(config.clientId, config.clientSecret, config.idPhoneNumber, config.idWaBusiness, config.token);
var httpWaRequest = DepGet<IHttpWaClient>();
httpWaRequest.SetToken(waConfig);

var waTplMsg = new WaContactTplSend(
    config.mobilePhone,
    "template_token",
    "pt_BR",
    new BodyComponent(new Parameter("text", "123456")),
    new ButtonComponent(new Parameter("text", "123456"))
);

var resp = await httpWaRequest.SendOneContactByTplAsync(waTplMsg);

Sending Text Messages

using WhatsAppHelper.Models;

// ...

var config = GetConfig();
var waConfig = new WaConfig(config.clientId, config.clientSecret, config.idPhoneNumber, config.idWaBusiness, config.token);
var httpWaRequest = DepGet<IHttpWaClient>();
httpWaRequest.SetToken(waConfig);

var waMsg = new WaContactTextSend(
    config.mobilePhone,
    false,
    $"Teste envio mensagem via WhatsApp, '{DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}'"
);

var resp = await httpWaRequest.SendOneContactByTextAsync(waMsg);

Receiving WhatsApp Messages

using WhatsAppHelper.Factories;

// ...

var factory = DepGet<IWaMsgReceiveFactory>();
var json = "your_received_message_json_string_here";
var result = factory.GetResult(json)?.ToList();
// Process and handle the received messages as needed

whatsapphelper's People

Contributors

thjli avatar

Watchers

 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.