Add telemgram post api
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const slugify = require('slugify')
|
const slugify = require('slugify')
|
||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
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 jwennAwtisEpiId = async data => {
|
const jwennAwtisEpiId = async data => {
|
||||||
const awtis = await strapi.query('awtis').find({_id: data})
|
const awtis = await strapi.query('awtis').find({_id: data})
|
||||||
@@ -27,6 +33,8 @@ module.exports = {
|
|||||||
const previousPublishedAt = previousData.published_at
|
const previousPublishedAt = previousData.published_at
|
||||||
const currentPublished_at = data.published_at
|
const currentPublished_at = data.published_at
|
||||||
if (currentPublished_at != previousPublishedAt) {
|
if (currentPublished_at != previousPublishedAt) {
|
||||||
|
const message = `<b>Nouvelle publication</b> \xF0\x9F\x8E\xB6 \xF0\x9F\x94\xA5
|
||||||
|
\n${process.env.WEBSITE_URL}/teks/${previousData.slug}`
|
||||||
if (previousData.user) {
|
if (previousData.user) {
|
||||||
strapi.services.email.send(
|
strapi.services.email.send(
|
||||||
process.env.SMTP_FROM,
|
process.env.SMTP_FROM,
|
||||||
@@ -36,6 +44,8 @@ module.exports = {
|
|||||||
Vous pouvez le trouver à l'adresse ${process.env.WEBSITE_URL}/teks/${previousData.slug}`
|
Vous pouvez le trouver à l'adresse ${process.env.WEBSITE_URL}/teks/${previousData.slug}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await axios.post(`${MESSAGE_URL}&text=${message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user