Fork me on GitHub
#babashka
<
2020-04-19
>
penryu00:04:26

Yeah, that's fair. I might still be battling OOP ideas, where I want an intermediate value to compose later values, but not expose/export it.

penryu00:04:52

It looks like ^:private is an option, but that seems overkill for this case at least. 🙂

penryu00:04:34

@borkdude That transducer worked great, btw. Cheers!

borkdude07:04:45

@penryu imo let + def is ok. It’s more the nested defn + defs that are used for debugging but not production worthy

sogaiu07:04:13

ah, i totally assumed this was being thought of in the context of being inside a def-ish form. borkdude's comment seems more accurate.

mkvlr07:04:19

because I see env variables: does babashka support setting them or does it share the limitations of JMV Clojure?

borkdude07:04:08

@mkvlr Same limitation as JVM

mkvlr07:04:00

@borkdude makes sense, thanks

borkdude07:04:00

@mkvlr You can however set env vars for a child process created with ProcessBuilder or clojure.java.shell

👍 4
borkdude10:04:33

v0.0.88: add clojure.data.xml. See example script: https://github.com/borkdude/babashka/blob/master/examples/pom_version.clj and a bunch of other enhancements/fixes. https://github.com/borkdude/babashka/releases/tag/v0.0.88

🎉 4
raydel9522:04:59

hello, i have a little question, i’m writing a little script in babashka to check a website status and trying to send some logs back to slack i have this curl

curl -X POST --form "payload={\"username\": \"webhookbot\", \"text\": \"This is posted to #general and comes from a bot named webhookbot.\", \"icon_emoji\": \":ghost:\"}" <path>
that works fine i tried to translated to babashka.curl but i got `400` on the all the requests here are the functions I tried:
(defn send-to-slack [url text]
        (curl/post url {:form-params {"payload" {"username" "webhookbot", "text" text, "icon_emoji" ":ghost:"}}}))
(defn send-to-slack [url text]
        (curl/post url {:form-params {:payload (json/encode {"username" "webhookbot", "text" text, "icon_emoji" ":ghost:"})}}))
i’m sure that i’m doing somthing wrong with the `:form-params` , i look at the docs but i didn’t find anything useful in this case, can somebody help me see what am i doing wrong? thanks in advance 🙂

nate23:04:12

what is url in this case?

nate23:04:16

a webhook url?

raydel9523:04:48

here is the url I was trying to send the messages

nate23:04:04

interesting

nate23:04:13

I am able to replicate the curl line

nate23:04:18

in my shell

nate23:04:22

and I see a 400 in my repl

nate23:04:06

hm, fiddling with it a bit

nate23:04:55

@UGTEF0BKL I can post with this function:

(defn send-to-slack [url text]
  (curl/post url {:body (json/encode {"text" text})}))

nate23:04:22

from https://api.slack.com/messaging/webhooks > You cannot override the default channel (chosen by the user who installed your app), username, or icon when you're using Incoming Webhooks to post messages. Instead, these values will always inherit from the associated Slack app configuration.

nate23:04:32

can't override username or icon

raydel9523:04:02

it works, thanks

nate23:04:40

you're welcome, glad to help

👍 4
raydel9523:04:39

@U0510902N that way to do the request is equivalent to this one

curl -X POST --data "{\"username\": \"webhookbot\", \"text\": \"text\", \"icon_emoji\": \":ghost:\"}" 
no? i’m still wondering why the other way doesn’t work :thinking_face:

nate23:04:05

yeah, it's curious

nate23:04:20

I've done some slack stuff and I haven't seen that payload version that you had before

nate23:04:28

maybe it's an older way of integrating

raydel9523:04:06

you mean in the curl or in the babashka version?

raydel9500:04:04

that curl was the one that slack gave me when i created the hook

raydel9500:04:54

thanks again, i can continue working in my script with that request

nate00:04:06

hm, that is odd

nate00:04:17

glad you have something to work forward with

👍 4
borkdude09:04:21

I found this also works:

(defn slack! [text]
  (when slack-hook-url
    (let [json (generate-string {:username "borkdude"
                                 :channel channel
                                 :text text})]
      (curl/post slack-hook-url
                 {:form-params {"payload" json}}))))

borkdude09:04:12

so it was probably an issue with :payload vs "payload"

borkdude09:04:00

and you have to manually transform the payload into json yourself

nate23:04:11

hm, looks like you're heading in the right direction

nate23:04:28

lemme try on my side

👍 4