MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 430 forks source link

How could I post to Slack from OpenOS? #2480

Closed NonlinearFruit closed 7 years ago

NonlinearFruit commented 7 years ago

Any ideas how I could post messages to a Slack channel via an incoming web hook? I need to send a JSON payload to a URL and I'm not sure how I can do this from the api that internet.lua provides.

I tried this but it gives me an error:

local token = "..."
local url = "example.com:5432/hooks/"..token
local data = [[{
  'text': 'Example message',
  'attachments': [
    {
      'title': 'Example',
      'title_link': 'https://rocket.chat',
      'text': 'Rocket.Chat, the best open source chat',
      'image_url': 'https://rocket.chat/images/mockup.png',
      'color': '#764FA5'
    }
  ]
}
]]

net.request(url,data)
xarses commented 7 years ago

What error is received? make sure to use the https:// component, not the short url you have slack only accepts https.

You might want to pass your data through a json validator just to be sure it's valid, or grab a json lua library (looks valid, but you never know)

Also what versions of MC/OpenCopmuters are you using?

NonlinearFruit commented 7 years ago

The https:// worked! I tried all sorts of stuff, I can't believe I missed that. Thanks!

For future reference, here is the error. I also missed the first line: invalid address.

image