hedwig-im / hedwig

An Adapter-based Bot Framework for Elixir Applications
MIT License
650 stars 73 forks source link

undefined function Alfred.Robot.send/2 #42

Closed cheeyeo closed 8 years ago

cheeyeo commented 8 years ago

Hi

I have followed the intro and created Alfred.Robot and I'm trying to get the bot to send messages from an OTP app.

Even though I can locate the bot using Hedwig.whereis("alfred"), it keeps crashing with the following error:

20:50:32.849 [error] Process #PID<0.183.0> raised an exception
** (UndefinedFunctionError) undefined function Alfred.Robot.send/2
    (combover) AlfredRobot.send(#PID<0.161.0>, %Hedwig.Message{matches: nil, private: %{}, ref: nil, robot: nil, room: "myroom", text: "https://twitter.com/statuses/737733017519706112", type: "message", user: %{}})
    (elixir) lib/stream.ex:454: anonymous fn/4 in Stream.map/2
    (elixir) lib/stream.ex:1101: Stream.do_resource/5
    (elixir) lib/stream.ex:1247: Enumerable.Stream.do_each/4
    (elixir) lib/stream.ex:494: Stream.run/1

I'm not sure what I am missing??

The send function should be defined?

cheeyeo commented 8 years ago

After further investigation, it does not appear this is due to the fact that I'm using the console adapter.

The same error appears when using the Hedwig Slack adapter too:

17:04:03.332 [error] Process #PID<0.245.0> raised an exception
** (UndefinedFunctionError) undefined function Hedwigslack.Robot.send/2
    (hedwigslack) Hedwigslack.Robot.send(#PID<0.205.0>, %Hedwig.Message{matches: nil, private: %{}, ref: nil, robot: #PID<0.205.0>, room: "", text: "test text", type: "message", user: %Hedwig.User{id: nil, name: nil}})
    (elixir) lib/stream.ex:454: anonymous fn/4 in Stream.map/2
    (elixir) lib/stream.ex:1101: Stream.do_resource/5
    (elixir) lib/stream.ex:1247: Enumerable.Stream.do_each/4
    (elixir) lib/stream.ex:494: Stream.run/1
scrogson commented 8 years ago

Hi there @cheeyeo, you're looking for Hedwig.Robot.send/2. It takes the pid of the robot and a %Hedwig.Message{}.

Hope that helps.