Skip to content

Instantly share code, notes, and snippets.

@willrax
Last active October 30, 2017 20:21
Show Gist options
  • Save willrax/7625ebe8aeaf63e369a15787135a5dd8 to your computer and use it in GitHub Desktop.
Save willrax/7625ebe8aeaf63e369a15787135a5dd8 to your computer and use it in GitHub Desktop.
defmodule AlphabotWeb.IntercomController do
use AlphabotWeb, :controller
def new(conn, %{"topic" => "conversation.user.created"} = params) do
%{payload: params["data"]["item"]}
|> send_notification
json conn, %{}
end
def new(conn, _params), do: json conn, %{}
def send_notification(state) do
# [Insert lots of pattern matching and pulling information
# from the darkest depths of a JSON payload here]
params = [
{:channel, Alphabot.Channel.support},
{:icon_url, @bot_image},
{:username, "Intercom"},
{:as_user, false},
{:attachments, Poison.encode!([attachments])}
]
SlackClient.api("chat.postMessage", params)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment