Skip to content

Commit

Permalink
Add thread_id support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsickert committed Sep 27, 2022
1 parent 4543a29 commit 89094c0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ jobs:
embed-footer-text: "Foot text [test](https://google.com)"
embed-color: 15430476
embed-timestamp: "2021-09-24T02:17:53+0000"
- name: Discord Webhook Action to Thread
uses: ./
with:
webhook-url: ${{ secrets.WEBHOOK_URL }}
username: Bill
avatar-url: https://cdn.discordapp.com/avatars/742807869023322232/dd41912939ffccbea0276f70688fa0ec.webp?size=256
thread-id: ${{ secrets.TEST_THREAD_ID }}
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Want to know more about Discord Webhooks? Check out the [intro](https://support.

## Recent Updates

- Support for Thread ID added (v5.3.0)
- Add Description Character limit truncation (v5.2.0)
- Support for embed URL (v5.1.0)
- Support for multiple operating systems (v5.0.0)
Expand All @@ -22,6 +23,7 @@ Want to know more about Discord Webhooks? Check out the [intro](https://support.
|-----------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| webhook-url | `true` | Webhook URL from discord. See: the [intro to webhook docs](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) for details |
| content | `false` | Message that is sent via the webhook |
| thread-id | `false` | ID of the thread you want the webhook to send the message into (will automatically unarchive threads) |
| username | `false` | The username that should appear to send the message. Note: username will have the "bot" badge next to their name |
| avatar-url | `false` | URL for the avatar that should appear with the message |
| tts | `false` | Whether the message is text-to-speech |
Expand All @@ -42,6 +44,8 @@ Want to know more about Discord Webhooks? Check out the [intro](https://support.

## Usage

Want to see some full examples? Check out the [`test`](https://github.com/tsickert/discord-webhook/blob/4543a29f31afb1608487e8d9cb3d380975669316/.github/workflows/test.yml) workflow!

### Secrets

_PSA_: Do not commit your webhook URL to a public repository. Webhooks do not require authentication, so anyone who has the webhook can use it.
Expand All @@ -63,7 +67,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Discord Webhook Action
uses: tsickert/discord-webhook@v5.2.0
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.WEBHOOK_URL }}
content: "Test"
Expand All @@ -82,7 +86,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Discord Webhook Action
uses: tsickert/discord-webhook@v5.2.0
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.WEBHOOK_URL }}
content: "Test"
Expand Down Expand Up @@ -146,7 +150,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Discord Webhook Action
uses: tsickert/discord-webhook@v5.2.0
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.WEBHOOK_URL }}
raw-data: hi.json
Expand Down Expand Up @@ -190,7 +194,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Discord Webhook Action
uses: tsickert/discord-webhook@v5.2.0
uses: tsickert/discord-webhook@v5.3.0
with:
webhook-url: ${{ secrets.WEBHOOK_URL }}
filename: test.txt
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ inputs:
required: true
content:
description: 'Message that is sent via the webhook.'
required: true
required: false
thread-id:
description: 'ID of the thread you want the webhook to send the message into (will automatically unarchive threads)'
required: false
username:
description: 'The username that should appear to send the message. Note: username will have the "bot" badge next to their name.'
required: false
Expand Down
7 changes: 6 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const URL = 'url'
const ICON_URL = 'icon-url'
const TEXT = 'text'
const FILENAME = 'filename'
const THREAD_ID = 'thread-id'

const TOP_LEVEL_WEBHOOK_KEYS = [CONTENT, USERNAME, AVATAR_URL]
const EMBED_KEYS = [TITLE, DESCRIPTION, TIMESTAMP, COLOR, URL]
Expand Down Expand Up @@ -130,10 +131,15 @@ async function handleResponse(response: TypedResponse<unknown>): Promise<void> {

export async function executeWebhook(): Promise<void> {
const client = new HttpClient()
const webhookUrl = core.getInput(WEBHOOK_URL)
let webhookUrl = core.getInput(WEBHOOK_URL)
const filename = core.getInput(FILENAME)
const threadId = core.getInput(THREAD_ID)
const payload = createPayload()

if (threadId !== '') {
webhookUrl = `${webhookUrl}?thread_id=${threadId}`
}

if (filename !== '') {
const formData = new FormData()
formData.append('upload-file', createReadStream(filename))
Expand Down

0 comments on commit 89094c0

Please sign in to comment.