Slack Bots With
Hedwig
Self Promotion
• Erik DeBill
• @edebill and @parsenome on twitter
• https://github.com/edebill
Spredfast Pays Me
• https://www.spredfast.com/
• We’ve got lots of really interesting problems and
a truly polyglot architecture
Hedwig Slack
• Plugin for hedwig-im
• You need to use the
github/master version instead
of published hex.pm
• Maintainer answers questions
in #hedwig channel on Elixir
slack
• Documentation is fairly good
for the basics
• See Elixir Sips episodes
Bootstrapping
• follow steps on Hedwig_slack
README
• mix new myapp —sup
• cd myapp
• add hedwig_slack to deps
• mix deps.get
• mix deps.compile
Robot Generator
• Works about like you’d expect
• Prompts you to add a worker
to your supervision tree. If you
didn’t add the —sup option
when you ran mix new this will
be hard to figure out
Config.exs
• Last of the boilerplate
• Follow README on how to
add to config.exs
• I recommend 2 tokens - one
dev, one test (rate limits will
eat you)
• Responders are where the
interesting stuff live
Getting a Token
Responders
• modules that use
Hedwig.Responder
• ‘hear’ and ‘respond’ macros
• chime in vs answer question
• can regex capture
At this point, we’ve
covered all the basics
from the docs
after_connect
• Called after connection
established
• Use to register bot so outside
code can find it
Sending Without
Responders
• Figure out pid for your bot
• Figure out channel id
(IO.inspect inside a responder
works great - these remain
stable forever)
• Format a Hedwig.Message
with room, text, and type
Suggestions
• “hear” responders will respond to ANYTHING that matches -
including help message output and things the bot says in a channel
• Generally stick to “respond” style responders
• Keep real app logic outside responders
• Consider starting with your bot inside an umbrella app
• Hedwig_slack locks a version of cowlib that conflicts with phoenix.
Can’t run them inside same app.
• Get 2 tokens (1 prod, 1 dev)
• Make a dedicated channel for bot testing
Erik DeBill
@edebill
erik@debill.org

Austin Elixir: Slack Bots With Hedwig

  • 1.
  • 2.
    Self Promotion • ErikDeBill • @edebill and @parsenome on twitter • https://github.com/edebill
  • 3.
    Spredfast Pays Me •https://www.spredfast.com/ • We’ve got lots of really interesting problems and a truly polyglot architecture
  • 4.
    Hedwig Slack • Pluginfor hedwig-im • You need to use the github/master version instead of published hex.pm • Maintainer answers questions in #hedwig channel on Elixir slack • Documentation is fairly good for the basics • See Elixir Sips episodes
  • 5.
    Bootstrapping • follow stepson Hedwig_slack README • mix new myapp —sup • cd myapp • add hedwig_slack to deps • mix deps.get • mix deps.compile
  • 6.
    Robot Generator • Worksabout like you’d expect • Prompts you to add a worker to your supervision tree. If you didn’t add the —sup option when you ran mix new this will be hard to figure out
  • 7.
    Config.exs • Last ofthe boilerplate • Follow README on how to add to config.exs • I recommend 2 tokens - one dev, one test (rate limits will eat you) • Responders are where the interesting stuff live
  • 8.
  • 9.
    Responders • modules thatuse Hedwig.Responder • ‘hear’ and ‘respond’ macros • chime in vs answer question • can regex capture
  • 10.
    At this point,we’ve covered all the basics from the docs
  • 11.
    after_connect • Called afterconnection established • Use to register bot so outside code can find it
  • 12.
    Sending Without Responders • Figureout pid for your bot • Figure out channel id (IO.inspect inside a responder works great - these remain stable forever) • Format a Hedwig.Message with room, text, and type
  • 13.
    Suggestions • “hear” responderswill respond to ANYTHING that matches - including help message output and things the bot says in a channel • Generally stick to “respond” style responders • Keep real app logic outside responders • Consider starting with your bot inside an umbrella app • Hedwig_slack locks a version of cowlib that conflicts with phoenix. Can’t run them inside same app. • Get 2 tokens (1 prod, 1 dev) • Make a dedicated channel for bot testing
  • 14.