Move packages/apps back
This commit is contained in:
parent
6eaaf8e9be
commit
5535d6b575
348 changed files with 0 additions and 0 deletions
62
packages/metamigo-db/records/voice/voice-line.ts
Normal file
62
packages/metamigo-db/records/voice/voice-line.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import {
|
||||
RepositoryBase,
|
||||
recordInfo,
|
||||
UUID,
|
||||
Flavor,
|
||||
} from "common";
|
||||
import type { } from "pg-promise";
|
||||
|
||||
export type VoiceLineId = Flavor<UUID, "VoiceLine Id">;
|
||||
|
||||
export type VoiceLineAudio = {
|
||||
"audio/webm": string;
|
||||
"audio/mpeg"?: string;
|
||||
checksum?: string;
|
||||
};
|
||||
|
||||
export interface UnsavedVoiceLine {
|
||||
providerId: string;
|
||||
providerLineSid: string;
|
||||
number: string;
|
||||
language: string;
|
||||
voice: string;
|
||||
promptText?: string;
|
||||
promptAudio?: VoiceLineAudio;
|
||||
audioPromptEnabled: boolean;
|
||||
audioConvertedAt?: Date;
|
||||
}
|
||||
|
||||
export interface SavedVoiceLine extends UnsavedVoiceLine {
|
||||
id: VoiceLineId;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const VoiceLineRecord = recordInfo<UnsavedVoiceLine, SavedVoiceLine>(
|
||||
"app_public",
|
||||
"voice_lines"
|
||||
);
|
||||
|
||||
export class VoiceLineRecordRepository extends RepositoryBase(VoiceLineRecord) {
|
||||
/**
|
||||
* Fetch all voice lines given the numbers
|
||||
* @param numbers
|
||||
*/
|
||||
async findAllByNumbers(numbers: string[]): Promise<SavedVoiceLine[]> {
|
||||
return this.db.any(
|
||||
"SELECT id,provider_id,provider_line_sid,number FROM $1 WHERE number in ($2:csv)",
|
||||
[this.schemaTable, numbers]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all voice lines given a list of provider line ids
|
||||
* @param ids
|
||||
*/
|
||||
async findAllByProviderLineSids(ids: string[]): Promise<SavedVoiceLine[]> {
|
||||
return this.db.any(
|
||||
"SELECT id,provider_id,provider_line_sid,number FROM $1 WHERE provider_line_sid in ($2:csv)",
|
||||
[this.schemaTable, ids]
|
||||
);
|
||||
}
|
||||
}
|
||||
52
packages/metamigo-db/records/voice/voice-provider.ts
Normal file
52
packages/metamigo-db/records/voice/voice-provider.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { RepositoryBase, recordInfo, UUID, Flavor } from "common";
|
||||
|
||||
/*
|
||||
* VoiceProvider
|
||||
*
|
||||
* A provider is a company that provides incoming voice call services
|
||||
*/
|
||||
|
||||
export type VoiceProviderId = Flavor<UUID, "VoiceProvider Id">;
|
||||
|
||||
export enum VoiceProviderKinds {
|
||||
TWILIO = "TWILIO",
|
||||
}
|
||||
|
||||
export type TwilioCredentials = {
|
||||
accountSid: string;
|
||||
apiKeySid: string;
|
||||
apiKeySecret: string;
|
||||
};
|
||||
|
||||
// expand this type later when we support more providers
|
||||
export type VoiceProviderCredentials = TwilioCredentials;
|
||||
|
||||
export interface UnsavedVoiceProvider {
|
||||
kind: VoiceProviderKinds;
|
||||
name: string;
|
||||
credentials: VoiceProviderCredentials;
|
||||
}
|
||||
|
||||
export interface SavedVoiceProvider extends UnsavedVoiceProvider {
|
||||
id: VoiceProviderId;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const VoiceProviderRecord = recordInfo<
|
||||
UnsavedVoiceProvider,
|
||||
SavedVoiceProvider
|
||||
>("app_public", "voice_providers");
|
||||
|
||||
export class VoiceProviderRecordRepository extends RepositoryBase(
|
||||
VoiceProviderRecord
|
||||
) {
|
||||
async findByTwilioAccountSid(
|
||||
accountSid: string
|
||||
): Promise<SavedVoiceProvider | null> {
|
||||
return this.db.oneOrNone(
|
||||
"select * from $1 where credentials->>'accountSid' = $2",
|
||||
[this.schemaTable, accountSid]
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue