Compare commits
6 Commits
01c234782e
...
3cf0188a8e
Author | SHA1 | Date | |
---|---|---|---|
3cf0188a8e | |||
4da9429e6e | |||
d9ac440498 | |||
ac30269c81 | |||
1d4b0cbac3 | |||
83784bec8f |
17
src/db/migrations/20210314175439_fromName_null.ts
Normal file
17
src/db/migrations/20210314175439_fromName_null.ts
Normal 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();
|
||||
})
|
||||
);
|
||||
}
|
31
src/index.ts
31
src/index.ts
@ -4,6 +4,8 @@ import { Sonar, gql } from "./sonar";
|
||||
import { SDK } from "@ringcentral/sdk";
|
||||
import { ticketize } from "./ticketize";
|
||||
|
||||
export const DEBUG = !!process.env.DEBUG;
|
||||
|
||||
function checkEnv() {
|
||||
[
|
||||
"SONAR_URL",
|
||||
@ -68,16 +70,31 @@ async function initRingCentralSDK() {
|
||||
clientId: process.env.RC_APP_KEY,
|
||||
clientSecret: process.env.RC_APP_SECRET,
|
||||
});
|
||||
|
||||
const login = () =>
|
||||
sdk.login({
|
||||
username: process.env.RC_LOGIN_USERNAME,
|
||||
extension: process.env.RC_LOGIN_EXT,
|
||||
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, (err) => {
|
||||
console.error(err);
|
||||
});
|
||||
await sdk.login({
|
||||
username: process.env.RC_LOGIN_USERNAME,
|
||||
extension: process.env.RC_LOGIN_EXT,
|
||||
password: process.env.RC_LOGIN_PASSWORD,
|
||||
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.");
|
||||
|
||||
return sdk;
|
||||
}
|
||||
|
||||
|
@ -5,19 +5,21 @@ import { DateTime } from "luxon";
|
||||
import type { Contact } from "./types";
|
||||
import type { StoredVoicemail, StoredRecording } from "knex/types/tables";
|
||||
|
||||
export function getTicketSubject(
|
||||
voicemail: StoredVoicemail,
|
||||
contact?: Contact
|
||||
) {
|
||||
return `New Voicemail from ${getNationalNumber(voicemail.fromNumber)} (${
|
||||
contact ? contact.name : voicemail.fromName
|
||||
})`;
|
||||
function fromName(vm: StoredVoicemail, contact?: Contact) {
|
||||
return contact?.name ?? vm.fromName ?? "unknown";
|
||||
}
|
||||
|
||||
export function getTicketSubject(vm: StoredVoicemail, contact?: Contact) {
|
||||
const name = fromName(vm, contact);
|
||||
return `New Voicemail from ${getNationalNumber(vm.fromNumber)} (${name})`;
|
||||
}
|
||||
|
||||
export function getTicketBody(
|
||||
vm: StoredVoicemail & StoredRecording,
|
||||
contact?: Contact
|
||||
) {
|
||||
const name = fromName(vm, contact);
|
||||
|
||||
return ReactDOMServer.renderToStaticMarkup(
|
||||
<div>
|
||||
<div>
|
||||
@ -25,8 +27,7 @@ export function getTicketBody(
|
||||
{DateTime.fromISO(vm.received).toLocaleString(DateTime.DATETIME_MED)}
|
||||
</div>
|
||||
<div>
|
||||
<b>From:</b> {getNationalNumber(vm.fromNumber)} (
|
||||
{contact?.name ?? vm.fromName})
|
||||
<b>From:</b> {getNationalNumber(vm.fromNumber)} ({name})
|
||||
</div>
|
||||
<div>
|
||||
<b>To:</b> {getNationalNumber(vm.toNumber)}x{vm.extensionNumber} (
|
||||
|
@ -296,7 +296,7 @@ export function ticketize(
|
||||
*/
|
||||
async function getMissingTranscriptionVoicemails() {
|
||||
return await db("voicemails")
|
||||
.whereNotNull("transcription")
|
||||
.whereNull("transcription")
|
||||
.whereNotIn("transcriptionStatus", [
|
||||
// Don't include those whose transcriptions have failed or will not
|
||||
// be completed.
|
||||
|
Loading…
Reference in New Issue
Block a user