// Google Voice web API message shapes, from the reverse-engineered definitions // in mautrix-gvoice (pkg/libgv/gvproto). Only the fields we use are listed. import type { Schema } from './proto' export const ThreadFolder = { ALL_THREADS: 1, TEXT_THREADS: 2 } as const export const MessageType = { MISSED_CALL: 0, INCOMING_CALL: 1, VOICEMAIL: 2, OUTGOING_CALL: 7, SMS_IN: 10, SMS_OUT: 11, OUTGOING_CALL_CANCELLED: 14 } as const export const AttachmentStatus = { AVAILABLE: 1, NOT_SUPPORTED: 3 } as const export const SizeSpec = { ORIGINAL: 1 } as const // Media types sendsms accepts, by MIME type. export const SendMediaType: Record = { 'image/jpeg': 1, 'image/png': 2, 'image/tiff': 3, 'image/gif': 4, 'image/bmp': 5, 'image/webp': 6 } const Contact: Schema = { name: { n: 1, t: 'string' }, phoneNumber: { n: 2, t: 'string' }, blocked: { n: 7, t: 'bool' } } const AttachmentMetadata: Schema = { size: { n: 1, t: 'int' }, width: { n: 2, t: 'int' }, height: { n: 3, t: 'int' } } const Attachment: Schema = { mimeType: { n: 1, t: 'string' }, id: { n: 2, t: 'string' }, status: { n: 3, t: 'int' }, metadata: { n: 4, t: AttachmentMetadata, rep: true }, mediaType: { n: 5, t: 'int' } } const MMSMessage: Schema = { text: { n: 1, t: 'string' }, subject: { n: 2, t: 'string' }, attachments: { n: 3, t: Attachment, rep: true }, participants: { n: 4, t: Contact, rep: true }, senderPhoneNumber: { n: 5, t: 'string' } } export const Message: Schema = { id: { n: 1, t: 'string' }, timestamp: { n: 2, t: 'int' }, // epoch ms contact: { n: 4, t: Contact }, type: { n: 5, t: 'int' }, status: { n: 6, t: 'int' }, text: { n: 10, t: 'string' }, mms: { n: 15, t: MMSMessage }, transactionId: { n: 18, t: 'int' } } export const Thread: Schema = { id: { n: 1, t: 'string' }, read: { n: 2, t: 'bool' }, messages: { n: 3, t: Message, rep: true }, // newest first paginationToken: { n: 4, t: 'string' }, contacts: { n: 5, t: Contact, rep: true }, isText: { n: 8, t: 'bool' }, phoneNumbers: { n: 9, t: 'string', rep: true } } export const ThreadAttributes: Schema = { threadId: { n: 1, t: 'string' }, read: { n: 4, t: 'bool' } } const UnknownWrapper: Schema = { unknownInt2: { n: 2, t: 'int' }, unknownInt3: { n: 3, t: 'int' } } // ---- requests (sent as pblite) ---- export const ReqGetAccount: Schema = { unknownInt2: { n: 2, t: 'int' } } export const ReqListThreads: Schema = { folder: { n: 1, t: 'int' }, unknownInt2: { n: 2, t: 'int' }, unknownInt3: { n: 3, t: 'int' }, paginationToken: { n: 4, t: 'string' }, versionToken: { n: 5, t: 'string' }, unknownWrapper: { n: 6, t: UnknownWrapper } } export const ReqGetThread: Schema = { threadId: { n: 1, t: 'string' }, maybeMessageCount: { n: 2, t: 'int' }, paginationToken: { n: 3, t: 'string' }, unknownWrapper: { n: 4, t: UnknownWrapper } } export const ReqSendSMS: Schema = { text: { n: 5, t: 'string' }, threadId: { n: 6, t: 'string' }, recipients: { n: 7, t: 'string', rep: true }, transactionId: { n: 9, t: { id: { n: 1, t: 'int' } } }, media: { n: 10, t: { type: { n: 1, t: 'int' }, data: { n: 2, t: 'bytes' } } }, trackingData: { n: 11, t: { data: { n: 1, t: 'string' } } } } export const ReqUpdateAttributes: Schema = { attributes: { n: 1, t: ThreadAttributes }, otherAttributes: { n: 2, t: ThreadAttributes }, unknownInt: { n: 3, t: 'int' } } export const ReqCreateWaa: Schema = { requestKey: { n: 1, t: 'string' } } export const ReqPingWaa: Schema = { requestKey: { n: 1, t: 'string' }, payload: { n: 2, t: 'string' }, i1: { n: 3, t: 'int' }, i2: { n: 4, t: 'int' } } // ---- responses (binary protobuf, except WAA's pblite) ---- const PhoneNumber: Schema = { e164: { n: 1, t: 'string' } } export const RespGetAccount: Schema = { account: { n: 1, t: { primaryDestinationId: { n: 1, t: 'string' }, phones: { n: 3, t: { accountPhone: { n: 1, t: { phoneNumber: { n: 1, t: PhoneNumber } } } }, rep: true } } } } export const RespListThreads: Schema = { threads: { n: 1, t: Thread, rep: true }, paginationToken: { n: 2, t: 'string' }, versionToken: { n: 3, t: 'string' } } export const RespGetThread: Schema = { thread: { n: 1, t: Thread } } export const RespSendSMS: Schema = { threadId: { n: 2, t: 'string' }, threadItemId: { n: 3, t: 'string' }, timestampMs: { n: 4, t: 'int' } } export const RespEmpty: Schema = {} export const RespCreateWaa: Schema = { waa: { n: 1, t: { respId: { n: 1, t: 'string' }, interpreterUrl: { n: 3, t: { url: { n: 4, t: 'string' } } }, interpreterHash: { n: 4, t: 'string' }, program: { n: 5, t: 'string' }, globalName: { n: 6, t: 'string' } } } } // ---- typed views of decoded messages ---- export interface GvContact { name: string phoneNumber: string blocked: boolean } export interface GvAttachment { mimeType: string id: string status: number metadata: Array<{ size: number; width: number; height: number }> } export interface GvMessage { id: string timestamp: number contact?: GvContact type: number text: string mms?: { text: string; subject: string; attachments: GvAttachment[]; senderPhoneNumber: string; participants: GvContact[] } transactionId: number } export interface GvThread { id: string read: boolean messages: GvMessage[] paginationToken: string contacts: GvContact[] isText: boolean phoneNumbers: string[] }