Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/jump_tickets/done_notifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ defmodule JumpTickets.Ticket.DoneNotifier do
ticket_id: ticket_id,
slack_channel: slack_channel,
intercom_conversations: convs
} = ticket
} = _ticket
) do
slack_message = "Ticket #{ticket_id} has been marked as Done."

# Post to Slack
with {:ok, _} <- post_slack_message(slack_channel, slack_message) do
:ok
Expand Down Expand Up @@ -56,7 +55,6 @@ defmodule JumpTickets.Ticket.DoneNotifier do
parts = String.split(path, "/")
channel_id = Enum.at(parts, 3)
Slack.post_message(channel_id, message)

_ ->
{:error, :invalid_slack_channel_url}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jump_tickets/external/slack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ defmodule JumpTickets.External.Slack do
end
end

def post_message("" <> _, text), do: nil
# def post_message("" <> _, text), do: nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the bug! nice work


@doc """
Posts a message to a channel
Expand Down
25 changes: 20 additions & 5 deletions lib/jump_tickets_web/controllers/ticket_done_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,31 @@ defmodule JumpTicketsWeb.TicketDoneController do

Expects a JSON payload with the `page_id` key.
"""
def notion_webhook(conn, %{"page_id" => page_id}) do
with %Ticket{} = ticket <- Notion.get_ticket_by_page_id(page_id),
def notion_webhook(conn, params) do

with {:ok, page_id} <- get_page_id_from_params(params),
%Ticket{} = ticket <- Notion.get_ticket_by_page_id(page_id),
:ok <- DoneNotifier.notify_ticket_done(ticket) do
json(conn, %{status: "ok", message: "Ticket done notification sent."})
else
error ->
# Log or handle error as needed
{:error, error} ->
conn
|> put_status(500)
|> json(%{status: "error", error: inspect(error)})
|> json(%{status: "error", error: error})
end

end

defp get_page_id_from_params(params) do
case Map.get(params, "entity") do
nil ->
{:error, "Missing 'entity' in webhook payload"}

entity ->
case Map.get(entity, "id") do
nil -> {:error, "Missing 'id' in 'entity' of webhook payload"}
page_id -> {:ok, page_id}
end
end
end
end
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"floki": {:hex, :floki, "0.37.0", "b83e0280bbc6372f2a403b2848013650b16640cd2470aea6701f0632223d719e", [:mix], [], "hexpm", "516a0c15a69f78c47dc8e0b9b3724b29608aa6619379f91b1ffa47109b5d0dd3"},
"gettext": {:hex, :gettext, "0.26.2", "5978aa7b21fada6deabf1f6341ddba50bc69c999e812211903b169799208f2a8", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "aa978504bcf76511efdc22d580ba08e2279caab1066b76bb9aa81c4a1e0a32a5"},
"hackney": {:hex, :hackney, "1.23.0", "55cc09077112bcb4a69e54be46ed9bc55537763a96cd4a80a221663a7eafd767", [:rebar3], [{:certifi, "~> 2.14.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "6cd1c04cd15c81e5a493f167b226a15f0938a84fc8f0736ebe4ddcab65c0b44e"},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized"]},
"hpax": {:hex, :hpax, "1.0.2", "762df951b0c399ff67cc57c3995ec3cf46d696e41f0bba17da0518d94acd4aac", [:mix], [], "hexpm", "2f09b4c1074e0abd846747329eaa26d535be0eb3d189fa69d812bfb8bfefd32f"},
"httpoison": {:hex, :httpoison, "2.2.2", "15420e9e5bbb505b931b2f589dc8be0c3b21e2a91a2c6ba882d99bf8f3ad499d", [:mix], [{:hackney, "~> 1.21", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "de7ac49fe2ffd89219972fdf39b268582f6f7f68d8cd29b4482dacca1ce82324"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
Expand Down
3 changes: 2 additions & 1 deletion test/jump_tickets_web/controllers/error_html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule JumpTicketsWeb.ErrorHTMLTest do
end

test "renders 500.html" do
assert render_to_string(JumpTicketsWeb.ErrorHTML, "500", "html", []) == "Internal Server Error"
assert render_to_string(JumpTicketsWeb.ErrorHTML, "500", "html", []) ==
"Internal Server Error"
end
end