github.com/Jeffail/benthos/v3@v3.65.0/template/outputs/discord.yaml (about)

     1  name: discord
     2  type: output
     3  status: experimental
     4  categories: [ Services, Social ]
     5  summary: Writes messages to a Discord channel.
     6  description: |
     7    This output POSTs messages to the `/channels/{channel_id}/messages` Discord API endpoint authenticated as a bot using token based authentication.
     8  
     9    If the format of a message is a JSON object matching the [Discord API message type](https://discord.com/developers/docs/resources/channel#message-object) then it is sent directly, otherwise an object matching the API type is created with the content of the message added as a string.
    10  
    11  fields:
    12    - name: channel_id
    13      description: A discord channel ID to write messages to.
    14      type: string
    15  
    16    - name: bot_token
    17      description: A bot token used for authentication.
    18      type: string
    19  
    20    - name: rate_limit
    21      description: An optional rate limit resource to restrict API requests with.
    22      type: string
    23      default: ""
    24      advanced: true
    25  
    26  mapping: |
    27    root.http_client.url = "https://discord.com/api/channels/%v/messages".format(this.channel_id)
    28    root.http_client.rate_limit = this.rate_limit
    29    root.http_client.verb = "POST"
    30    root.http_client.headers."Content-Type" = "application/json"
    31    root.http_client.headers.Authorization = "Bot " + this.bot_token
    32    root.http_client.max_in_flight = 64
    33    root.http_client.batch_as_multipart = false
    34    root.processors = []
    35    root.processors."-".bloblang = """
    36      root = if (this | {}).exists("content") { this } else {
    37        { "content": content().string() }
    38      }
    39    """
    40  
    41  tests:
    42    - name: Basic fields
    43      config:
    44        channel_id: 1234
    45        rate_limit: foolimit
    46        bot_token: foobot
    47  
    48      expected:
    49        http_client:
    50          url: https://discord.com/api/channels/1234/messages
    51          verb: POST
    52          headers:
    53            Content-Type: application/json
    54            Authorization: Bot foobot
    55          rate_limit: foolimit
    56          batch_as_multipart: false
    57          max_in_flight: 64
    58        processors:
    59          - bloblang: |
    60              root = if (this | {}).exists("content") { this } else {
    61                { "content": content().string() }
    62              }