@rodrigo.ribeiro has joined the channel
I made a script for a Slack bot! I’m pretty pleased that I am beginning to understand how to read Racket docs :slightly_smiling_face:
(define bot-token (getenv "TOKEN"))
(define json-file (getenv "JSON_FILE"))
(port->string
(post-pure-port
(string->url "<https://slack.com/api/chat.postMessage>")
(jsexpr->bytes (string->jsexpr (read-file json-file)))
(list "Content-Type: application/json;charset=utf-8"
(format "Authorization: Bearer ~a" bot-token))))
Next up: error handling!
ooh! I’ve wanted to have some Slack bots here.
turns out it’s pretty easy, the hardest bit was realizing that I didn’t need to do an OAuth exchange because when you register a bot you’re given a full bearer token to start with
interesting, thank you :slightly_smiling_face:
ever since we mostly moved to slack i’ve missed having it around
@c Nice! One tiny point is that code leaves the input port (the value that post-pure-port
returns) open. Maybe prefer call/input-url
. e.g. https://www.greghendershott.com/2013/08/using-call-input-url.html
As an excercise you could, for example, oh I don’t know… have your Slack bot look for mentions of xxx-pure-port
and automatically post a link to that blog post!!! :wink:
Haha that actually sounds really funny. I’ll see what I can do! :sweat_smile:
Unfortunately it appears call/input-url
can’t actually be applied to post-pure-port
:
call/input-url: contract violation
expected: a procedure that accepts 1 non-keyword argument
given: #<procedure:post-pure-port>
post-pure-port accepts: 2 or 3 arguments
the problem is that post-pure-port
requires a body, hence the arity mismatch :confused: