Message is not sent from external module
Closed this issue · 1 comments
maksimf commented
I am trying to send a message to Slack and I have a separate module to do that:
defmodule Slack.MessagePoster do
@slack_bot Slack.Bot
@slack_api_key "API_KEY"
def send_message!(channel, message) do
{:ok, rtm} = @slack_bot.start_link(Slack.MyRtm, [], @slack_api_key)
{:message, _, _} = send(rtm, {:message, message, channel})
end
end
And I call it as (inside iex -S mix
)
MyRtm
looks like this:
defmodule Slack.MyRtm do
use Slack
def handle_connect(slack, state) do
IO.puts "Connected as #{slack.me.name}"
{:ok, state}
end
def handle_event(_, _, state), do: {:ok, state}
def handle_info({:message, text, channel}, slack, state) do
IO.puts "Sending message, text: #{text}, channel: #{channel}"
send_message(text, channel, slack)
{:ok, state}
end
def handle_info(_, _, state), do: {:ok, state}
end
Slack.MessagePoster.send_message!("#general", "Never mind me, I'm just a test message")
I get {:message, "Never mind me, I'm just a test message", "#general"}
as a response, but nothing get posted to Slack. But, if just bypass my send_message!/2
call and call this directly
{:ok, rtm} = @slack_bot.start_link(Slack.MyRtm, [], @slack_api_key)
{:message, _, _} = send(rtm, {:message, message, channel})
Everything works as expected (I see message in the Slack). Do you know what might be the problem here?
BlakeWilliams commented
Hey @maksimf nothing stands out here, is there any chance you have a working repo I could pull and test this out and maybe debug it a little bit?