-
-
Notifications
You must be signed in to change notification settings - Fork 113
feat: add http adapter #231
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
214d078
feat: add http adapter
efekrskl 5c0775d
feat: make request example collapsible
efekrskl cbfaeb3
refactor: fix typo
efekrskl adc131a
fix: make auth optional for http adapter
efekrskl 0e60b76
docs: improve http adapter docs
efekrskl 8aca737
fix: adjust label
efekrskl 1ba06d6
docs: mention bearer token
efekrskl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { markdown2Html } from '../../services/markdown.js'; | ||
|
|
||
| const mapListing = (listing) => ({ | ||
| address: listing.address, | ||
| description: listing.description, | ||
| id: listing.id, | ||
| imageUrl: listing.image, | ||
| price: listing.price, | ||
| size: listing.size, | ||
| title: listing.title, | ||
| url: listing.link, | ||
| }); | ||
|
|
||
| export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => { | ||
| const { authToken, endpointUrl } = notificationConfig.find((a) => a.id === config.id).fields; | ||
|
|
||
| const listings = newListings.map(mapListing); | ||
| const body = { | ||
| jobId: jobKey, | ||
| timestamp: new Date().toISOString(), | ||
| provider: serviceName, | ||
| listings, | ||
| }; | ||
|
|
||
| const headers = { | ||
| 'Content-Type': 'application/json', | ||
| }; | ||
| if (authToken != null) { | ||
| headers['Authorization'] = `Bearer ${authToken}`; | ||
| } | ||
|
|
||
| return fetch(endpointUrl, { | ||
| method: 'POST', | ||
| headers: headers, | ||
| body: JSON.stringify(body), | ||
| }); | ||
| }; | ||
|
|
||
| export const config = { | ||
| id: 'http', | ||
| name: 'HTTP', | ||
| readme: markdown2Html('lib/notification/adapter/http.md'), | ||
| description: 'Fredy will send a generic HTTP POST request.', | ||
| fields: { | ||
| endpointUrl: { | ||
| description: "Your application's endpoint URL.", | ||
| label: 'Endpoint URL', | ||
| type: 'text', | ||
| }, | ||
| authToken: { | ||
| description: "Your application's auth token, if required by your endpoint.", | ||
| label: 'Auth token (optional)', | ||
| optional: true, | ||
| type: 'text', | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ### HTTP Adapter | ||
|
|
||
| This is a generic adapter for sending notifications via HTTP requests. | ||
| You can leverage this adapter to integrate with various webhooks or APIs that accept HTTP requests. (e.g. Supabase | ||
| Functions, a Node.js server, etc.) | ||
|
|
||
| HTTP adapter supports a `authToken` field, which can be used to include an authorization token in the request headers. | ||
| Your token would be included as a Bearer token in the `Authorization` header, which is a common method for securing API requests. | ||
|
|
||
| Request Details: | ||
| <details> | ||
| Request Method: POST | ||
|
|
||
| Headers: | ||
|
|
||
| ``` | ||
| Content Type: `application/json` | ||
| Authorization: Bearer {your-optional-auth-token} | ||
| ``` | ||
|
|
||
| Body: | ||
|
|
||
| ```json | ||
| { | ||
| "jobId": "mg1waX4RHmIzL5NDYtYp-", | ||
| "provider": "immoscout", | ||
| "timestamp": "2024-06-15T12:34:56Z", | ||
| "listings": [ | ||
| { | ||
| "address": "Str. 123, Bielefeld, Germany", | ||
| "description": "Möbliert: Einziehen & wohlfühlen: Neu möbliert.", | ||
| "id": "123456789", | ||
| "imageUrl": "https://<target-url>.com/listings/123456789.jpg", | ||
| "price": "1.240 €", | ||
| "size": "38 m²", | ||
| "title": "Schöne 1-Zimmer-Wohnung in Bielefeld", | ||
| "url": "https://<target-url>.com/listings/123456789" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| </details> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge it this time, but in the future, please make sure to install the pre-commit hooks. If you do, it would have told you that double quotes are not allowed. I'll fix this later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string has a single quote inside, therefore it doesn't raise any issues. This is how similar usages are handled (e.g.
lib/notification/adapter/telegram.js:122)