remove unused
This commit is contained in:
@@ -5,7 +5,7 @@ import path from 'path';
|
|||||||
import { google, gmail_v1 } from 'googleapis';
|
import { google, gmail_v1 } from 'googleapis';
|
||||||
import { OAuth2Client } from 'google-auth-library';
|
import { OAuth2Client } from 'google-auth-library';
|
||||||
|
|
||||||
import { ASSISTANT_NAME, MAIN_GROUP_FOLDER } from '../config.js';
|
import { MAIN_GROUP_FOLDER } from '../config.js';
|
||||||
import { logger } from '../logger.js';
|
import { logger } from '../logger.js';
|
||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
@@ -39,10 +39,7 @@ export class GmailChannel implements Channel {
|
|||||||
private threadMeta = new Map<string, ThreadMeta>();
|
private threadMeta = new Map<string, ThreadMeta>();
|
||||||
private userEmail = '';
|
private userEmail = '';
|
||||||
|
|
||||||
constructor(
|
constructor(opts: GmailChannelOpts, pollIntervalMs = 60000) {
|
||||||
opts: GmailChannelOpts,
|
|
||||||
pollIntervalMs = 60000,
|
|
||||||
) {
|
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
this.pollIntervalMs = pollIntervalMs;
|
this.pollIntervalMs = pollIntervalMs;
|
||||||
}
|
}
|
||||||
@@ -87,14 +84,12 @@ export class GmailChannel implements Channel {
|
|||||||
// Verify connection
|
// Verify connection
|
||||||
const profile = await this.gmail.users.getProfile({ userId: 'me' });
|
const profile = await this.gmail.users.getProfile({ userId: 'me' });
|
||||||
this.userEmail = profile.data.emailAddress || '';
|
this.userEmail = profile.data.emailAddress || '';
|
||||||
logger.info(
|
logger.info({ email: this.userEmail }, 'Gmail channel connected');
|
||||||
{ email: this.userEmail },
|
|
||||||
'Gmail channel connected',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Start polling
|
// Start polling
|
||||||
this.pollTimer = setInterval(
|
this.pollTimer = setInterval(
|
||||||
() => this.pollForMessages().catch((err) =>
|
() =>
|
||||||
|
this.pollForMessages().catch((err) =>
|
||||||
logger.error({ err }, 'Gmail poll error'),
|
logger.error({ err }, 'Gmail poll error'),
|
||||||
),
|
),
|
||||||
this.pollIntervalMs,
|
this.pollIntervalMs,
|
||||||
@@ -218,7 +213,8 @@ export class GmailChannel implements Channel {
|
|||||||
|
|
||||||
const headers = msg.data.payload?.headers || [];
|
const headers = msg.data.payload?.headers || [];
|
||||||
const getHeader = (name: string) =>
|
const getHeader = (name: string) =>
|
||||||
headers.find((h) => h.name?.toLowerCase() === name.toLowerCase())?.value || '';
|
headers.find((h) => h.name?.toLowerCase() === name.toLowerCase())
|
||||||
|
?.value || '';
|
||||||
|
|
||||||
const from = getHeader('From');
|
const from = getHeader('From');
|
||||||
const subject = getHeader('Subject');
|
const subject = getHeader('Subject');
|
||||||
@@ -259,10 +255,15 @@ export class GmailChannel implements Channel {
|
|||||||
|
|
||||||
// Find the main group to deliver the email notification
|
// Find the main group to deliver the email notification
|
||||||
const groups = this.opts.registeredGroups();
|
const groups = this.opts.registeredGroups();
|
||||||
const mainEntry = Object.entries(groups).find(([, g]) => g.folder === MAIN_GROUP_FOLDER);
|
const mainEntry = Object.entries(groups).find(
|
||||||
|
([, g]) => g.folder === MAIN_GROUP_FOLDER,
|
||||||
|
);
|
||||||
|
|
||||||
if (!mainEntry) {
|
if (!mainEntry) {
|
||||||
logger.debug({ chatJid, subject }, 'No main group registered, skipping email');
|
logger.debug(
|
||||||
|
{ chatJid, subject },
|
||||||
|
'No main group registered, skipping email',
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user