const axios = require('axios');
const fs = require('fs');
exports.runQuery = function (matrixClient, room, registrar) {
setInterval(() => {
axios({
method: 'GET',
url: `${registrar.config.fediverse.domain}/api/v1/notifications`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
}).then((notifications) => {
const event = fs.readFileSync('notification.json', 'utf8');
fs.writeFileSync('notification.json', notifications.data[0].created_at, 'utf8');
if (event !== notifications.data[0].created_at) {
if (notifications.data[0].type === 'follow') {
matrixClient.sendHtmlNotice(room.roomId,
'',
`
${notifications.data[0].account.acct}
has followed you.
${notifications.data[0].account.note}`);
} else if (notifications.data[0].type === 'favourite') {
matrixClient.sendHtmlNotice(room.roomId,
'',
`
${notifications.data[0].account.acct}
has favorited
your post:
${notifications.data[0].status.content}`); } else if (notifications.data[0].type === 'mention') { matrixClient.sendHtmlNotice(room.roomId, '', ` ${notifications.data[0].account.acct} has mentioned you:
${notifications.data[0].status.content}`); } else if (notifications.data[0].type === 'reblog') { matrixClient.sendHtmlNotice(room.roomId, '', ` ${notifications.data[0].account.acct} has repeated your post:
(id: ${notifications.data[0].status.id}) ${registrar.media.visibilityEmoji(notifications.data[0].status.visibility)}
${notifications.data[0].status.content}`); } } }); }, 8000); };