Compare commits

...

6 Commits

Author SHA1 Message Date
3cf0188a8e Add DEBUG RingCentral request logging 2021-03-14 12:26:44 -06:00
4da9429e6e Allow fromName to be null 2021-03-14 12:17:42 -06:00
d9ac440498 Handle refresh errors by re-authenticating 2021-03-14 12:16:59 -06:00
ac30269c81 Fix getMisisngTranscriptionVoicemails
Meant whereNull, not whereNotNull.
2021-03-13 15:08:14 -07:00
1d4b0cbac3 Add request logging 2021-03-13 15:05:53 -07:00
83784bec8f Improve refresh error logging 2021-03-13 14:51:32 -07:00
4 changed files with 52 additions and 17 deletions

View File

@ -0,0 +1,17 @@
import { Knex } from "knex";
export async function up(knex: Knex) {
return knex.transaction((trx) =>
trx.schema.alterTable("voicemails", (table) => {
table.string("fromName", 64).alter();
})
);
}
export async function down(knex: Knex) {
return knex.transaction((trx) =>
trx.schema.alterTable("voicemails", (table) => {
table.string("fromName", 64).notNullable().alter();
})
);
}

View File

@ -4,6 +4,8 @@ import { Sonar, gql } from "./sonar";
import { SDK } from "@ringcentral/sdk"; import { SDK } from "@ringcentral/sdk";
import { ticketize } from "./ticketize"; import { ticketize } from "./ticketize";
export const DEBUG = !!process.env.DEBUG;
function checkEnv() { function checkEnv() {
[ [
"SONAR_URL", "SONAR_URL",
@ -68,16 +70,31 @@ async function initRingCentralSDK() {
clientId: process.env.RC_APP_KEY, clientId: process.env.RC_APP_KEY,
clientSecret: process.env.RC_APP_SECRET, clientSecret: process.env.RC_APP_SECRET,
}); });
const platform = sdk.platform();
platform.on(platform.events.refreshError, (err) => { const login = () =>
console.error(err); sdk.login({
});
await sdk.login({
username: process.env.RC_LOGIN_USERNAME, username: process.env.RC_LOGIN_USERNAME,
extension: process.env.RC_LOGIN_EXT, extension: process.env.RC_LOGIN_EXT,
password: process.env.RC_LOGIN_PASSWORD, password: process.env.RC_LOGIN_PASSWORD,
}); });
if (DEBUG) {
const client = sdk.client();
client.on(client.events.beforeRequest, (req) => {
console.log(req.url);
});
}
const platform = sdk.platform();
platform.on(platform.events.refreshError, async (err) => {
console.error("Refresh token error:", err);
await login();
console.log("RingCentral re-authentication successful.");
});
await login();
console.log("Authenticated to RingCentral."); console.log("Authenticated to RingCentral.");
return sdk; return sdk;
} }

View File

@ -5,19 +5,21 @@ import { DateTime } from "luxon";
import type { Contact } from "./types"; import type { Contact } from "./types";
import type { StoredVoicemail, StoredRecording } from "knex/types/tables"; import type { StoredVoicemail, StoredRecording } from "knex/types/tables";
export function getTicketSubject( function fromName(vm: StoredVoicemail, contact?: Contact) {
voicemail: StoredVoicemail, return contact?.name ?? vm.fromName ?? "unknown";
contact?: Contact }
) {
return `New Voicemail from ${getNationalNumber(voicemail.fromNumber)} (${ export function getTicketSubject(vm: StoredVoicemail, contact?: Contact) {
contact ? contact.name : voicemail.fromName const name = fromName(vm, contact);
})`; return `New Voicemail from ${getNationalNumber(vm.fromNumber)} (${name})`;
} }
export function getTicketBody( export function getTicketBody(
vm: StoredVoicemail & StoredRecording, vm: StoredVoicemail & StoredRecording,
contact?: Contact contact?: Contact
) { ) {
const name = fromName(vm, contact);
return ReactDOMServer.renderToStaticMarkup( return ReactDOMServer.renderToStaticMarkup(
<div> <div>
<div> <div>
@ -25,8 +27,7 @@ export function getTicketBody(
{DateTime.fromISO(vm.received).toLocaleString(DateTime.DATETIME_MED)} {DateTime.fromISO(vm.received).toLocaleString(DateTime.DATETIME_MED)}
</div> </div>
<div> <div>
<b>From:</b> {getNationalNumber(vm.fromNumber)} ( <b>From:</b> {getNationalNumber(vm.fromNumber)} ({name})
{contact?.name ?? vm.fromName})
</div> </div>
<div> <div>
<b>To:</b> {getNationalNumber(vm.toNumber)}x{vm.extensionNumber} ( <b>To:</b> {getNationalNumber(vm.toNumber)}x{vm.extensionNumber} (

View File

@ -296,7 +296,7 @@ export function ticketize(
*/ */
async function getMissingTranscriptionVoicemails() { async function getMissingTranscriptionVoicemails() {
return await db("voicemails") return await db("voicemails")
.whereNotNull("transcription") .whereNull("transcription")
.whereNotIn("transcriptionStatus", [ .whereNotIn("transcriptionStatus", [
// Don't include those whose transcriptions have failed or will not // Don't include those whose transcriptions have failed or will not
// be completed. // be completed.