hedwig-im/hedwig_xmpp

Name: hedwig_xmpp

Owner: Hedwig IM

Description: XMPP Adapter for Hedwig

Created: 2015-11-27 21:29:35.0

Updated: 2017-09-27 03:30:24.0

Pushed: 2017-03-15 16:35:24.0

Homepage:

Size: 23

Language: Elixir

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Hedwig XMPP Adapter

An XMPP Adapter for Hedwig

Getting started

Let's generate a new Elixir application with a supervision tree:

x new alfred --sup
eating README.md
eating .gitignore
eating mix.exs
eating config
eating config/config.exs
eating lib
eating lib/alfred.ex
eating test
eating test/test_helper.exs
eating test/alfred_test.exs

 Mix project was created successfully.
can use "mix" to compile it, test it, and more:

cd alfred
mix test

"mix help" for more commands.

Change into our new application directory:

 alfred

Add hedwig_xmpp to your list of dependencies in mix.exs:

deps do
{:hedwig_xmpp, "~> 1.0"}]

Ensure hedwig_xmpp is started before your application:

application do
pplications: [:hedwig_xmpp]]

Generate our robot
x hedwig.gen.robot

ome to the Hedwig Robot Generator!

s get started.

 would you like to name your bot?: alfred

lable adapters

edwig.Adapters.XMPP
edwig.Adapters.Console
edwig.Adapters.Test

se select an adapter: 1

eating lib/alfred
eating lib/alfred/robot.ex
dating config/config.exs

t forget to add your new robot to your supervision tree
ically in lib/alfred.ex):

worker(Alfred.Robot, [])
Supervise our robot

We'll want Alfred to be supervised and started when we start our application. Let's add it to our supervision tree. Open up lib/alfred.ex and add the following to the children list:

er(Alfred.Robot, [])
Configuration

The next thing we need to do is configure our bot for our XMPP server. Open up config/config.exs and let's take a look at what was generated for us:

Mix.Config

ig :alfred, Alfred.Robot,
apter: Hedwig.Adapters.XMPP,
me: "alfred",
a: "/",
sponders: [
{Hedwig.Responders.Help, []},
{Hedwig.Responders.Ping, []}

So we have the adapter, name, aka, and responders set. The adapter is the module responsible for handling all of the XMPP details like connecting and sending and receiving messages over the network. The name is the name that our bot will respond to. The aka (also known as) field is optional, but it allows us to address our bot with an alias. By default, this alias is set to /.

Finally we have responders. Responders are modules that provide functions that match on the messages that get sent to our bot. We'll discuss this further in a bit.

We'll need to provide a few more things in order for us to connect to our XMPP server. We'll need to provide our bot's jid and password as well as a list of rooms we want our bot to join once connected. Let's see what that looks like:

Mix.Config

ig :alfred, Alfred.Robot,
apter: Hedwig.Adapters.XMPP,
me: "alfred",
a: "/",
fill in the appropriate jid for your bot
d: "alfred@localhost",
fill in the appropriate password for your bot
ssword: "password",
oms: [
# fill in the appropriate rooms for your XMPP server
{"lobby@conference.localhost", []}

sponders: [
{Hedwig.Responders.Help, []},
{Hedwig.Responders.Ping, []}

Great! We're ready to start our bot. From the root of our application, let's run the following:

x run --no-halt

This will start our application along with our bot. Our bot should connect to the server and join the configured room(s). From there, we can connect with our favourite XMPP client and begin sending messages to our bot.

Since we have the Help responder installed, we can say alfred help and we should see a list of usage for all of the installed responders.

What's next?

Well, that's it for now. Make sure to read the Hedwig Documentation for more details on writing responders and other exciting things!

LICENSE

Copyright (c) 2015, Sonny Scroggin.

Hedwig XMPP source code is licensed under the MIT License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.