Skip to content

3. WebRequests

coffeeRequired edited this page Mar 6, 2024 · 3 revisions

SkJson

Pages - WebRequests

What are and how do webRequests work in SkJson how can I use them, what is possible and what methods work

WebRequest

We can create a new web request and set need fields as like body/headers/attachments and then we will ecexute that

    set {_request} to prepare new GET request on "https://raw.githubusercontent.com/SkJsonTeam/skJson/main/skjson.jsonn"
    set {_request}'s request content to @{"A": true}
    set {_request}'s headers to @{"Content-Type": "application/json+vhd"}
    send prepared {_request}

    if response status of {_request} is "OK":
        send response content of {_request}
        send response status code of {_request}
        send response headers of {_request}

@PrepareRequest

allowed methods are [GET, POST, PUT, HEAD, MOCK, DELETE, PATCH] allowed value type of content is Json or stringify json (Json as String) e.g. "{""Test"": true}" allowed value type of header is Json or (Pairs e.g. "Content-Type: application/Json", "Allow: restrict") You can execute the request by 'send prepared {_request}', otherwise the request will be not sent, but the request will be still stored

@SendRequest

Send prepared/created request to the given method and uri

@PropertiesAttachment

set/add/reset or get the current request attachment

@PropertiesContent

set/reset or get the current request content

@PropertiesHeader

set/reset or get the current request headers

@Response

get all response properties

WebHooks / Discord Hooks

What is Webhooks => Webhook is a web address (URL) that you can set in the administration and the system sends messages / data to this address according to the selected rules. In the webhook settings you define the URL, the data format and the event to which the data is sent. The system takes care of the rest.

1. Discord

  • For discord we can send files, embeds, we have available settings
  • header (string|json)
  • attachment | attachments
    • If it is an attachment then only one file can be attached! but if it's attachments we can attach as many files as we want using key: value
      • 1: ./test.sk
      • 2: ./test2.sk
  • data (nested format)
    • username (string)
    • avatar-url (string)
    • tts (boolean)
    • content (string ! Cannot be null, shall be empty)
    • embed (nested format)
      • id (int|null|auto)
      • fields (string-json)
      • title (string)
      • thumbnail (nested json | json)
      • color (hex color. e.g. ##21a7c2)

2. Web

  • For web we can send files, we have available settings
  • attachment | attachments
    • If it is an attachment then only one file can be attached! but if it's attachments we can attach as many files as we want using key: value
  • content | contents
    • If it is an content then only one line can be posted! but if it's contents we can post as many lined as we want using key: value
      • 1: This is random text
      • 2: This is a random text 2
  • header (string|json)

3. Examples

command web:
   trigger:
       async send web request "https://webhook.site/>4e2e350b-4a8f-4863-85c5-e833e4ec110b":
           attachments:
               1: "C:\\Users\\nexti\\Documents\\Lekce\\index.html"
           content: "{fromSkJson: '?', ?: true}"
           
           
command without-embed:
   trigger:
       async send discord request "https://discord.com/api/webhooks/>1128075537919770798/>y78NK-odks6Lod5kimmhcd9YWQfhFzPU1YA-VyD5bqWMGxaeYXxp5jTxpnNI9Yhw1Rgt":
           header: "Content-Type: application/json"
           data:
               tts: true
               content: "{'payload:' true}" # this can be any json encoded string or >json
           
           
command embed:
   trigger:
       async send discord request "https://discord.com/api/webhooks/>1128075537919770798/>y78NK-odks6Lod5kimmhcd9YWQfhFzPU1YA-VyD5bqWMGxaeYXxp5jTxpnNI9Yhw1Rgt":
           header: "Content-Type: application/json"
           data:
               username: "AAAA"
               avatar-url: "https://google.com"
               tts: true
               content: "" # content never can be empty, so when you want to send >only embed, you need to put here empty string
               embed:
                   id: 102018 # when you put here null, or auto, the value will be >generated automatically.
                   fields: "{}"
                   author: "{name: 'CoffeeRequired'}"
                   title: "Hello there"
                   thumbnail: "{url: 'https://cravatar.eu/helmhead/_F0cus__/600.png'}"
                   color: "##21a7c2" # that support all hex colors.. not minecraft
           
command embedAtt:
   trigger:
       async send discord request "https://discord.com/api/webhooks/>1128075537919770798/>y78NK-odks6Lod5kimmhcd9YWQfhFzPU1YA-VyD5bqWMGxaeYXxp5jTxpnNI9Yhw1Rgt":
           attachments:
               1: "*/generate_doc.sk" # star means the parser will search for the >file recursively from the root directory
           data:
               tts: false
               content: "hello from attachments"
Clone this wiki locally