From 93966ef4309a54d51de193f05cd19dfa599b707e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Wed, 31 Jul 2024 18:14:48 +0200 Subject: [PATCH] Add Revolt publishing --- .env.example | 6 ++++++ .../parole/content-types/parole/lifecycles.js | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/.env.example b/.env.example index be9407c..c06a92a 100644 --- a/.env.example +++ b/.env.example @@ -34,3 +34,9 @@ TELEGRAM_API_TOKEN= DEEPL_URL= DEEPL_KEY= + +# Revolt + +REVOLT_BOT_ID= +REVOLT_TARGET= +REVOLT_TOKEN= diff --git a/src/api/parole/content-types/parole/lifecycles.js b/src/api/parole/content-types/parole/lifecycles.js index e0e9fbf..6820322 100644 --- a/src/api/parole/content-types/parole/lifecycles.js +++ b/src/api/parole/content-types/parole/lifecycles.js @@ -10,6 +10,9 @@ const TELEGRAM_API_URL = 'https://api.telegram.org' const TELEGRAM_CHAN_ID = process.env.TELEGRAM_CHAN_ID || null const TELEGRAM_API_TOKEN = process.env.TELEGRAM_API_TOKEN || null const MESSAGE_URL = `${TELEGRAM_API_URL}/bot${TELEGRAM_API_TOKEN}/sendMessage?chat_id=${TELEGRAM_CHAN_ID}&parse_mode=html` +const REVOLT_BOT_ID = process.env.REVOLT_BOT_ID || null +const REVOLT_TARGET = process.env.REVOLT_TARGET || null +const REVOLT_TOKEN = process.env.REVOLT_TOKEN || null const getSlug = (artiste, parole) => { return slugify(`${artiste}-${parole}`, {lower: true, remove: /[*#+~.()'"!:@]/g}) @@ -214,6 +217,24 @@ module.exports = { if (TELEGRAM_API_TOKEN) { await axios.post(`${MESSAGE_URL}&text=${message}`) } + + if (REVOLT_TOKEN && REVOLT_TARGET && REVOLT_BOT_ID) { + const revoltMessage = `Nouvelle publication ! + \n${process.env.WEBSITE_URL}/paroles/${previousData.slug}` + + const targetChannel = REVOLT_TARGET + const botToken = REVOLT_TOKEN + const url = `https://api.revolt.chat/channels/${targetChannel}/messages` + + const config = { + headers: { + 'X-Bot-Token': botToken, + 'Content-Type': 'application/json' + } + } + + await axios.post(url, {content: revoltMessage}, config) + } } } },