Merge pull request #109 from connorjclark/master

support thread-name and flags
This commit is contained in:
Thomas Sickert 2023-12-12 22:48:10 -05:00 committed by GitHub
commit d094b6e04e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 5 deletions

View file

@ -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 |

View file

@ -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

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View file

@ -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]
@ -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}`
)