Whatsapp Elixir Client


License
Apache-2.0

Documentation

Elixir CI

Build Status

Whatsapp Api

Cliente para comunicar con el servicio de Whatsapp https://developers.facebook.com/docs/whatsapp

  • Login
  • Logout
  • Create User
  • Create account
  • Verify account
  • Check contact
  • Send text messages
  • Send hsm messages
  • Send media messages
  • Download media
  • Delete media
  • Get application medatada
  • Update application metadata
  • Two step verification
  • Get health
  • Stats
  • Support

Installation

If available in Hex, the package can be installed by adding wax to your list of dependencies in mix.exs:

def deps do
  [
    {:wax, "~> 0.5.0"}
  ]
end

Setup default parser in config.ex

config :whatsapp_api,
  parser: Whatsapp.Parser,
  timeout: 50_000,
  connect_timeout: 50_000,
  recv_timeout: :infinity

Using GenServer Auth

defmodule MyApp.Application do
  use Application

  alias Whatsapp.Models.WhatsappProvider

  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  def start(_type, _args) do
    import Supervisor.Spec

    children = [
      worker(Whatsapp.Auth.Server, [[
        %WhatsappProvider{
          name: "My company",
          url: "https://wa.io:9090/v1",
          username: "username",
          password: "password"
        }
      ]])
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

Now you can use the provider name to authenticate

iex> %{"contacts" => [%{"wa_id" => wa_id}] = WhatsappApi.check("5566295500", "My company")
iex> message = MessageOutbound.new(to: wa_id, body: "Hi!")
iex> WhatsappApi.send(message, "My company")

Without GenServer Auth

iex> message = MessageOutbound.new(to: "wa_id", body: "Hi!")
iex> auth_header = [{"Authorization", "Bearer #{token}"}]
iex> Whatsapp.Api.Messages.send({"https://wa.io:9090/v1", auth_header, message)

Development iex Console

iex> Whatsapp.Auth.Server.start_link([%{name: "company", username: "username", password: "password", url: "https://wa.company.io:9090/v1"}])

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/wax.