Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(WebhookClient): allow creation of clients via URLs #6192

Merged
merged 2 commits into from Jul 29, 2021
Merged

feat(WebhookClient): allow creation of clients via URLs #6192

merged 2 commits into from Jul 29, 2021

Conversation

J-Human
Copy link
Contributor

@J-Human J-Human commented Jul 28, 2021

Please describe the changes this PR makes and why it should be merged:

This allows WebhookClient's to be made with URLs, without the need of removing it or doing any type of parsing. This is useful for pass-through services like Webhook senders, etc., allowing a more convenient time for developers who don't want to use IDs and tokens. Example:

import { WebhookClient } from 'discord.js';

const webhook = new WebhookClient({ url: 'https://discord.com/api/webhooks/1234567890/abc' });

webhook.send({ content: 'Hi.' });

This PR also updates:

  • Typings.
  • Errors (URLs are passed to a RegEx and validated, although 100% perfection is not possible).
  • Tests.

It now mandates initializing Webhook clients should have one object parameter, that can contain either ID + token or just a URL (this isn't validated so all 3 are optional).

Fixes #6164

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating
  • This PR changes the library's interface (methods or parameters added)
  • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)

src/client/WebhookClient.js Outdated Show resolved Hide resolved
src/client/WebhookClient.js Outdated Show resolved Hide resolved
src/errors/Messages.js Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
@iCrawl iCrawl added this to the Version 13 milestone Jul 28, 2021
@iCrawl iCrawl requested review from SpaceEEC and kyranet July 28, 2021 08:22
@J-Human
Copy link
Contributor Author

J-Human commented Jul 28, 2021

@vladfrangu fixed! Thanks for reminding. 😅

@J-Human J-Human requested a review from vladfrangu July 28, 2021 09:42
Copy link
Contributor

@NotSugden NotSugden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the constructor typings need updating still

src/client/WebhookClient.js Outdated Show resolved Hide resolved
src/client/WebhookClient.js Outdated Show resolved Hide resolved
@J-Human
Copy link
Contributor Author

J-Human commented Jul 29, 2021

@NotSugden @Jiralite done! Your suggestions have been committed. Thanks a lot.

  • According to Jiralite's comment (and Crawl's decision) - the discordapp domain in the RegExp has vanished.
  • As per Sugden's comment here, I updated the constructor typings for WebhookClient (yes, I forgot to do so), and retrieving the data from either the URL or ID, token has been refactored.

src/client/WebhookClient.js Outdated Show resolved Hide resolved
src/client/WebhookClient.js Show resolved Hide resolved
@J-Human
Copy link
Contributor Author

J-Human commented Jul 29, 2021

Done.

Copy link
Member

@iCrawl iCrawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it, I am actually in need of this too :D

@iCrawl iCrawl merged commit e000af5 into discordjs:master Jul 29, 2021
@J-Human J-Human deleted the feat/webhooks-from-urls branch July 29, 2021 10:49
@Alex-451
Copy link

Thanks for the addition @J-Human

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebhookClient creation with url
7 participants