const axios = require('axios'); const fs = require('fs'); exports.runQuery = function (matrixClient, room, registrar) { setInterval(() => { axios({ method: 'GET', url: `${registrar.config.fediverse}/api/v1/notifications`, headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, }).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}
[id: ${notifications.data[0].status.id}]
`); } else if (notifications.data[0].type === 'reblog') { matrixClient.sendHtmlNotice(room.roomId, '', `
${notifications.data[0].account.acct} has repeated your post:
${notifications.data[0].status.content}
`); } } }); }, 8000); };