Hedwig v1.0.0 Hedwig.Robot
Defines a robot.
Robots receive messages from a chat source (XMPP, Slack, Console, etc), and
dispatch them to matching responders. See the documentation for
Hedwig.Responder
for details on responders.
When used, the robot expects the :otp_app
as option. The :otp_app
should
point to an OTP application that has the robot configuration. For example,
the robot:
defmodule MyApp.Robot do
use Hedwig.Robot, otp_app: :my_app
end
Could be configured with:
config :my_app, MyApp.Robot,
adapter: Hedwig.Adapters.Console,
name: "alfred"
Most of the configuration that goes into the config
is specific to the
adapter. Be sure to check the documentation for the adapter in use for all
of the available options.
Robot configuration
adapter
- the adapter module name.name
- the name the robot will respond to.aka
- an alias the robot will respond to.log_level
- the level to use when logging output.responders
- a list of responders specified in the following format:{module, kwlist}
.
Summary
Functions
Send an emote message via the robot
Invokes a user defined handle_connect/1
function, if defined
Invokes a user defined handle_disconnect/1
function, if defined
Invokes a user defined handle_in/2
function, if defined
Get the name of the robot
Send a reply message via the robot
Get the list of the robot’s responders
Send a message via the robot
Functions
Invokes a user defined handle_connect/1
function, if defined.
If the user has defined an handle_connect/1
in the robot module, it will be
called with the robot’s state. It is expected that the function return
{:ok, state}
or {:stop, reason, state}
.
handle_disconnect(pid, any, integer) :: :reconnect | {:reconnect, integer} | {:disconnect, any}
Invokes a user defined handle_disconnect/1
function, if defined.
If the user has defined an handle_disconnect/1
in the robot module, it will be
called with the robot’s state. It is expected that the function return
{:reconnect, state}
{:reconnect, integer, state}
, or {:disconnect, reason, state}
.
Invokes a user defined handle_in/2
function, if defined.
This function should be called by an adapter when a message arrives but should be handled by the user module.
Returning {:dispatch, msg, state}
will dispatch the message
to all installed responders.
Returning {:send, {msg, text}, state}
, {:reply, {msg, text}, state}
,
or {:emote, {msg, text}, state}
will send the message directly to the
adapter without dispatching to any responders.
Returning {:noreply, state}
will ignore the message.