rodrigo.ribeiro
2020-5-5 14:57:06

@rodrigo.ribeiro has joined the channel


c
2020-5-5 20:59:14

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-&gt;string (post-pure-port (string-&gt;url "<https://slack.com/api/chat.postMessage>") (jsexpr-&gt;bytes (string-&gt;jsexpr (read-file json-file))) (list "Content-Type: application/json;charset=utf-8" (format "Authorization: Bearer ~a" bot-token)))) Next up: error handling!


samth
2020-5-5 21:06:04

ooh! I’ve wanted to have some Slack bots here.


c
2020-5-5 21:11:23

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


samth
2020-5-5 21:12:03

you might be interested in https://github.com/offby1/rudybot


c
2020-5-5 21:12:55

interesting, thank you :slightly_smiling_face:


samth
2020-5-5 21:13:14

ever since we mostly moved to slack i’ve missed having it around


greg
2020-5-6 01:36:53

@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


greg
2020-5-6 01:41:43

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:


c
2020-5-6 02:01:36

Haha that actually sounds really funny. I’ll see what I can do! :sweat_smile:


c
2020-5-6 03:39:34

Unfortunately it appears call/input-url can’t actually be applied to post-pure-port:


c
2020-5-6 03:39:39

call/input-url: contract violation expected: a procedure that accepts 1 non-keyword argument given: #&lt;procedure:post-pure-port&gt; post-pure-port accepts: 2 or 3 arguments


c
2020-5-6 03:40:09

the problem is that post-pure-port requires a body, hence the arity mismatch :confused: