Skip to content

Commit

Permalink
Merge pull request #109 from connorjclark/master
Browse files Browse the repository at this point in the history
support thread-name and flags
  • Loading branch information
tsickert authored Dec 13, 2023
2 parents 654311f + aeeddff commit d094b6e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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) |
| thread-name | `false` | Name of the thread you want the webhook to create |
| flags | `false` | Message flags |
| 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 Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ inputs:
thread-id:
description: 'ID of the thread you want the webhook to send the message into (will automatically unarchive threads)'
required: false
thread-name:
description: 'Name of the thread you want the webhook to create'
required: false
flags:
description: 'Message flags'
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
27 changes: 22 additions & 5 deletions 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.

27 changes: 22 additions & 5 deletions src/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const ICON_URL = 'icon-url'
const TEXT = 'text'
const FILENAME = 'filename'
const THREAD_ID = 'thread-id'
const THREAD_NAME = 'thread-name'
const FLAGS = 'flags'

const TOP_LEVEL_WEBHOOK_KEYS = [CONTENT, USERNAME, AVATAR_URL]
const EMBED_KEYS = [TITLE, DESCRIPTION, TIMESTAMP, COLOR, URL]
Expand Down Expand Up @@ -134,20 +136,35 @@ export async function executeWebhook(): Promise<void> {
let webhookUrl = core.getInput(WEBHOOK_URL)
const filename = core.getInput(FILENAME)
const threadId = core.getInput(THREAD_ID)
const threadName = core.getInput(THREAD_NAME)
const flags = core.getInput(FLAGS)
const payload = createPayload()

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

if (filename !== '') {
if (filename !== '' || threadName !== '' || flags !== '') {
const formData = new FormData()
formData.append('upload-file', createReadStream(filename))
formData.append('payload_json', JSON.stringify(payload))
if (filename !== '') {
formData.append('upload-file', createReadStream(filename))
formData.append('payload_json', JSON.stringify(payload))
}
if (threadName !== '') {
formData.append('thread_name', threadName)
}
if (flags !== '') {
formData.append('flags', Number(flags))
}
formData.submit(webhookUrl, function (error, response) {
if (error != null) {
core.error(`failed to upload file: ${error.message}`)
} else {
if (filename !== '') {
core.error(`failed to upload file: ${error.message}`)
}
if (threadName !== '') {
core.error(`failed to create thread: ${threadName}`)
}
} else if (filename !== '') {
core.info(
`successfully uploaded file with status code: ${response.statusCode}`
)
Expand Down

0 comments on commit d094b6e

Please sign in to comment.