Skip to content

Commit

Permalink
Auto-publish new video recording links to rocket chat
Browse files Browse the repository at this point in the history
  • Loading branch information
owenkellogg committed Dec 21, 2022
1 parent dae7571 commit 5834a11
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/actors/publish_new_recordings_to_rocketchat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

import { log } from 'rabbi'

export const exchange = 'powco'

export const queue = 'publish_new_recordings_to_rocketchat'

export const routingkey = 'jaas.8x8.vc.webhook'

import * as models from '../models'

import { notify } from '../rocketchat'

export default async function start(channel, msg, json) {

log.debug('rabbi.actor.publish_new_recordings_to_rocketchat', {
message: msg.content.toString(),
json
})

switch(json.eventType) {

case 'RECORDING_UPLOADED':

console.log('RECORDING_UPLOADED', json)

notify('powco-development', `A New POWCO Club Video Room Recording Was Uploaded:\n\n ${json.data.preAuthenticatedLink}\n\nEnjoy!!\n\n(please note this link is only available for 24 hours)`);

break;

default:

break;

}

channel.ack(msg)

}

44 changes: 44 additions & 0 deletions src/rocketchat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require('dotenv').config()

import { Actor, log } from 'rabbi'

import config from './config'

const http = require("superagent");

const base = 'https://chat.21e8.tech/hooks';

const channels = {
'misc': 'WPGC3DJvZSqR8xTcr/e5oBJAenhYsEijBpv8P3sKupdADLsAwzNk26TbT3nE2cDJmg',
'powco-development': config.get('rocketchat_channel_powco_development')
}

export function notify(channel, message: string) {

if (!channels[channel]) {
log.error(`rocketchat channel ${channel} not found`);
channel = 'misc';
}

log.debug(`notify rocketchat ${message}`);

http
.post(`${base}/${channels[channel]}`)
.send({
text: message
})
.end((error, response) => {
if (error) {
log.error("rocketchat.error", error.message);
} else {
log.info("rocketchat.notified", response.body);
}
});
}

export async function notifyRocketChat(message: string): Promise<void> {

return notify('misc', message)

}

0 comments on commit 5834a11

Please sign in to comment.