2880 timebox create a poc to fetch emails from the gmail api (#2993)

* create empty service

* getting threads is working

* insert message channel

* save threads in the db

* clean

* fetch messages

* create a service to fetch a batch of messages

* batch messages

* use httpService instead

* parse batch

* base 64 decoding working

* solve parsing bug

* saving messages is working

* bug to fix in fetchAllByBatches

* fetching all messages is working but not saving yet

* fecth 500 messages and threads is working

* remove unused package and console log

* set direction to incoming

* fix bug after merging main
This commit is contained in:
bosiraphael
2023-12-15 16:35:56 +01:00
committed by GitHub
parent ac3c517c82
commit f95c56b1cb
7 changed files with 412 additions and 7 deletions

View File

@ -1,5 +1,7 @@
import { Injectable } from '@nestjs/common';
import { v4 } from 'uuid';
import { DataSourceService } from 'src/metadata/data-source/data-source.service';
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
import { SaveConnectedAccountInput } from 'src/core/auth/dto/save-connected-account';
@ -43,10 +45,26 @@ export class GoogleGmailService {
return;
}
await workspaceDataSource?.query(
`INSERT INTO ${dataSourceMetadata.schema}."connectedAccount" ("handle", "provider", "accessToken", "refreshToken", "accountOwnerId") VALUES ($1, $2, $3, $4, $5)`,
[handle, provider, accessToken, refreshToken, workspaceMemberId],
);
const connectedAccountId = v4();
await workspaceDataSource?.transaction(async (manager) => {
await manager.query(
`INSERT INTO ${dataSourceMetadata.schema}."connectedAccount" ("id", "handle", "provider", "accessToken", "refreshToken", "accountOwnerId") VALUES ($1, $2, $3, $4, $5, $6)`,
[
connectedAccountId,
handle,
provider,
accessToken,
refreshToken,
workspaceMemberId,
],
);
await manager.query(
`INSERT INTO ${dataSourceMetadata.schema}."messageChannel" ("visibility", "handle", "connectedAccountId", "type") VALUES ($1, $2, $3, $4)`,
['share_everything', handle, connectedAccountId, 'gmail'],
);
});
return;
}