-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesv.coffee
35 lines (34 loc) · 1.24 KB
/
esv.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Description:
# Simple ESV passage lookup based on esv-api.org
#
# Commands:
# hubot esv <passage>
#
# Configuration:
# HUBOT_ESV_API_KEY (Authorization token header value without "Token")
#
# Notes:
# An API key from api.esv.org is required.
# Obtain one from https://api.esv.org/account/create-application/
# See https://api.esv.org/docs/passage-text/#required-parameters for syntax
#
# Author:
# Scott A. Williams <[email protected]>
module.exports = (robot) ->
robot.respond /esv\s+(.*)/i, (msg) ->
if not msg.match[1]
msg.send "Please provide a Bible passage for lookup"
return
else
passage = msg.match[1]
url = "https://api.esv.org/v3/passage/text/?q=" + passage + "&output-format=plain-text&include-footnotes=false&include-passage-horizontal-lines=false&include-heading-horizontal-lines=false&include-headings=false&include-subheadings=false&include-footnotes=false"
robot.http(url)
.header("Authorization","Token #{process.env.HUBOT_ESV_API_KEY}")
.get() (err, res, body) ->
if err
msg.send "We have a problem: #{err}"
return
else
data = JSON.parse body
msg.send passage for passage in data.passages
return