{"id":18671681,"url":"https://github.com/penseapp/discord-notification","last_synced_at":"2025-04-12T01:30:46.156Z","repository":{"id":42526361,"uuid":"333178033","full_name":"penseapp/discord-notification","owner":"penseapp","description":"A package to send formatted discord notifications","archived":false,"fork":false,"pushed_at":"2023-03-07T13:13:58.000Z","size":728,"stargazers_count":10,"open_issues_count":4,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T21:13:21.119Z","etag":null,"topics":["discord","discord-notification","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/penseapp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-26T18:27:56.000Z","updated_at":"2023-12-25T06:43:07.000Z","dependencies_parsed_at":"2024-06-21T16:52:46.474Z","dependency_job_id":"0eeecf7b-2f15-41f6-b4db-d26dc3f39eb3","html_url":"https://github.com/penseapp/discord-notification","commit_stats":{"total_commits":68,"total_committers":2,"mean_commits":34.0,"dds":"0.16176470588235292","last_synced_commit":"8933730a63b0aa05d7de70ca106482b05e1570ba"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penseapp%2Fdiscord-notification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penseapp%2Fdiscord-notification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penseapp%2Fdiscord-notification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penseapp%2Fdiscord-notification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/penseapp","download_url":"https://codeload.github.com/penseapp/discord-notification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055271,"owners_count":21040151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-notification","nodejs","typescript"],"created_at":"2024-11-07T09:06:44.968Z","updated_at":"2025-04-12T01:30:45.846Z","avatar_url":"https://github.com/penseapp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Discord notifications\n\n\n\u003cdiv align=\"center\"\u003e\n\n![npm](https://img.shields.io/npm/dw/@penseapp/discord-notification)\u003cbr\u003e\n[![npm version](https://badge.fury.io/js/@penseapp%2Fdiscord-notification.svg)](https://badge.fury.io/js/@penseapp%2Fdiscord-notification)\n![test](https://github.com/penseapp/discord-notification/workflows/test/badge.svg?branch=master)\n![GitHub Workflow Status (event)](https://img.shields.io/github/workflow/status/penseapp/discord-notification/test)\n[![Coverage Status](https://coveralls.io/repos/github/penseapp/discord-notification/badge.svg?branch=master)](https://coveralls.io/github/penseapp/discord-notification?branch=master)\n[![License Status](https://img.shields.io/github/license/penseapp/discord-notification)](https://img.shields.io/github/license/penseapp/discord-notification)\n\n[![Issues Status](https://img.shields.io/github/issues/penseapp/discord-notification)](https://img.shields.io/github/issues/penseapp/discord-notification)\n[![Tag Status](https://img.shields.io/github/v/tag/penseapp/discord-notification)](https://img.shields.io/github/v/tag/penseapp/discord-notification)\n[![Languages Status](https://img.shields.io/github/languages/count/penseapp/discord-notification)](https://img.shields.io/github/languages/count/penseapp/discord-notification)\n\u003c/div\u003e\n\n## Install steps\n\n```sh\nnpm i @penseapp/discord-notification\n```\nor\n```sh\nyarn add @penseapp/discord-notification\n```\n## How to use\n\nImport the package:\n```js\nimport { DiscordNotification } from '@penseapp/discord-notification'\n```\n\nInstantiate a new class of DiscordNotification passing the name and discord webhook \n```js\n// Name of the microservice / webhook of discord\nexport const discordNotification = new DiscordNotification('my-name', 'https://discordapp.com/api/webhooks/qNbqLQDB5mD7Rxr6')\n```\n\nCall discordNotification obj, see the example above\n```js\n// Get the variable in others files\ndiscordNotification\n  .sucessfulMessage()\n  .addTitle('My title')\n  .addDescription('My description')\n  .addField({name: 'Field 1', value: 'Content #1', inline: false }) //breakline\n  .addField({name: 'Field 2', value: 'Content #2' }) \n  .addField({name: 'Field 3', value: 'Content #3' }) \n  .addFooter('My footer') // Small text at the end of discord notification\n  .sendMessage()\n```\n\nThe output on discord will be:\n\n![image](https://user-images.githubusercontent.com/5152197/151089826-e50f6174-8152-46c9-b2ae-d1b230f7e47d.png)\n\n\n### messageTypes\nThere are 5 different messages\n\n```js\ndiscordNotification.message() // Shows message without color\ndiscordNotification.sucessfulMessage() // Shows green message\ndiscordNotification.infoMessage() // Shows Blue message\ndiscordNotification.errorMessage() // Shows red message\ndiscordNotification.warningMessage() // Shows orange message\n```\n\n### Examples\n\n```js\nimport { DiscordNotification } from \"./DiscordNotification\";\n\nexport const discordNotification = new DiscordNotification('my-name', 'https://discordapp.com/api/webhooks/qNbqLQDB5mD7Rxr6')\n  \ndiscordNotification\n  .sucessfulMessage()\n  .addTitle('My title')\n  .addDescription('My description')\n  .addField({name: 'Field 1', value: 'Content #1', inline: false }) //breakline\n  .addField({name: 'Field 2', value: 'Content #2' }) \n  .addField({name: 'Field 3', value: 'Content #3' }) \n  .addFooter('My footer') // Small text at the end of discord notification\n  .sendMessage()\n```\n\n#### you can use @here or @everyone if is something critical using `addContent`\n\n```js\ndiscordNotification\n  .errorMessage()\n  .addTitle('Error bla')\n  .addContent('@everyone')\n  .sendMessage()\n\ndiscordNotification\n  .errorMessage()\n  .addTitle('Error bla')\n  .addContent('@here looks here!')\n  .sendMessage()\n```\n\n#### Send formatted JSON\n\n```js\n\ndiscordNotification\n  .errorMessage()\n  .addTitle('Error bla')\n  .addContent('```json'+ '\\n' + JSON.stringify({ \"myjson\": \"bla\" }) +'```')\n  .sendMessage()\n``` \n\n#### Send formatted Stack error message\n\n```js\ntry {\n  throw new Error('My error')\n} catch (error) {\n  const e: Error = error as Error\n  discordNotification\n    .errorMessage()\n    .addTitle(e.message)\n    .addContent('```json'+ '\\n' + JSON.stringify({\n      \"teste\": \"teste\"\n      }) +'```')\n  .sendMessage()\n}\n```\n\n#### Other examples\n\n```js\ndiscordNotification\n  .sucessfulMessage()\n  .addTitle('Testing color green (success)')\n  .sendMessage()\n\ndiscordNotification\n  .errorMessage()\n  .addTitle('Testing color red (error)')\n  .sendMessage()\n\ndiscordNotification\n  .warningMessage()\n  .addTitle('Testing color orange (warning)')\n  .sendMessage()\n\ndiscordNotification\n  .infoMessage()\n  .addTitle('Testing color blue (info)')\n  .sendMessage()\n\ndiscordNotification\n  .message()\n  .addTitle('Testing no color')\n  .sendMessage()\n```\n\n### Discord webhook\n\n```\nOpen Discord -\u003e select the channel -\u003e Click on configuration -\u003e Integrations -\u003e View webhooks -\u003e New webhook\n```\n\nCreate a new webhook called `Discord notification` and add on Github secrets with a name of `DISCORD_CHANNEL_WEBHOOK`, like the GIF bellow:\n\n![Peek 2021-06-02 22-21](https://user-images.githubusercontent.com/5152197/121472497-aa56ec00-c997-11eb-83cb-b9f03094e5dd.gif)\n\nNow, you will receive the notifications on the desired discord channel.\n\n## Information\n\nThe tests does not pass on node version 10.*\nUse at your own risk.\n\nThe versions:\n- 12.x\n- 14.x\n- 16.x\n- 18.x\n\nAre working.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpenseapp%2Fdiscord-notification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpenseapp%2Fdiscord-notification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpenseapp%2Fdiscord-notification/lists"}