generated from typescriptstarter/ts-backend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-publish new video recording links to rocket chat
- Loading branch information
1 parent
dae7571
commit 5834a11
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
|