# ex_microsoft_teams

Elixir library for integration with Microsoft Teams Incoming Webhook.

> We hope that the use of this library could be enjoyable despite the fact of dealing with Microsoft Teams.
## Installation

If [available in Hex](, the package can be installed
by adding `ex_microsoft_teams` to your list of dependencies in `mix.exs`:

def deps do
    {:ex_microsoft_teams, "~> 0.1.0"}

## Usage

### Create a webhook in Microsoft Teams

    1. Navigate to the channel where you want to add the webhook and select (•••) Connectors from the top navigation bar.
    2. Search for Incoming Webhook, and add it.
    3. Click Configure and provide a name for your webhook.
    4. Copy the URL which appears and click "OK".

### Sending a message

webhook_url = "" 
message = "Hello World!!"
ExMicrosoftTeams.send_message(webhook_url, message)
=> {:ok, "Message sent!"}

|> ExMicrosoftTeams.client()
|> ExMicrosoftTeams.notify("Hello World!!")
=> {:ok, "Message sent!"}

## Testing

### Using [Mox](

# config/config.exs 
config :my_app, :microsoft_teams_client, ExMicrosoftTeams

# microsoft_teams_client.ex, the main context we chose to call this function from
defmodule MicrosoftTeamsClient do
  def send_message(message) do
    microsoft_teams_client().send_message(webhook_url(), message)

  defp webhook_url, do: ""

  defp microsoft_teams_client do
    Application.compile_env(:my_app, :microsoft_teams_client)

# In your test/test_helper.exs
Mox.defmock(ExMicrosoftTeamsMock, for: ExMicrosoftTeams.Base) # <- Add this
Application.put_env(:my_app, :microsoft_teams_client, ExMicrosoftTeamsMock) # <- Add this


# test/microsoft_teams_client_test.exs
defmodule MicrosoftTeamsClientTest do
  use ExUnit.Case

  import Mox

  setup :verify_on_exit!

  describe "send_message/1" do
    test "send message with the correct webhook_url and message" do
      expect(ExMicrosoftTeamsMock, :send_message, fn webhook_url, message ->
        # here we can assert on the arguments that get passed to the function
        assert webhook_url == ""
        assert message == "Hello World!"

        # here we decide what the mock returns
        {:ok, "Message sent!"}

      assert {:ok, _} = ExMicrosoftTeams.send_message("Hello World!")

Documentation can be generated with [ExDoc](
and published on [HexDocs]( Once published, the docs can
be found at <>.