ULX

Author Topic: Using webhooks in gmod  (Read 81 times)

0 Members and 1 Guest are viewing this topic.

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Using webhooks in gmod
« on: August 16, 2019, 11:08:22 PM »
So I'm kind of new to using webhooks and I haven't been able to figure this out so I would like some perspective from others.
Basically what I'm just trying to do is have messages relayed from garry's mod to discord.

I have tried some of the examples I have found online but none of them have seemed to work. The general idea of what I have is something like this

Code: Lua
  1. local webhook = "insertmywebhookhere"
  2.  
  3. hook.Add("PlayerSay", "discord_relay", function(ply, text)
  4.     http.Post(webook, {content = text}, nil, function(failed)
  5.         print("Something went wrong!")
  6.         print(failed)
  7.     end)
  8. end)

Any help would be appreciated!
Thanks

Offline Timmy

  • Ulysses Team Member
  • Full Member
  • *****
  • Posts: 217
  • Karma: 160
  • Code monkey
    • ULX Unofficial Documentation
Re: Using webhooks in gmod
« Reply #1 on: August 17, 2019, 08:39:04 AM »
It looks like Discord has blacklisted the User-Agent that Garry's Mod uses to make HTTP requests.

This can be verified with cURL:
Code: [Select]
# This works:
curl -X POST https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}?wait=true \
     -d content=Hello%20discord

# This doesn't:
curl -X POST https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}?wait=true \
     -H "User-Agent: Valve/Steam HTTP Client 1.0 (4000)"
     -d content=Hello%20discord

The User-Agent is hard coded and can not be changed. See: https://github.com/Facepunch/garrysmod-requests/issues/1365
“When given the choice between being right or being kind, choose kind.”  —Dr. Wayne Dyer

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Using webhooks in gmod
« Reply #2 on: August 17, 2019, 12:26:41 PM »
It looks like Discord has blacklisted the User-Agent that Garry's Mod uses to make HTTP requests.

This can be verified with cURL:
Code: [Select]
# This works:
curl -X POST https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}?wait=true \
     -d content=Hello%20discord

# This doesn't:
curl -X POST https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}?wait=true \
     -H "User-Agent: Valve/Steam HTTP Client 1.0 (4000)"
     -d content=Hello%20discord

The User-Agent is hard coded and can not be changed. See: https://github.com/Facepunch/garrysmod-requests/issues/1365

Ahhh that sucks
Thanks Timmy