add zapier integration

This commit is contained in:
chungyau97 2023-06-27 23:01:09 +08:00
parent 4e36be3214
commit dd8b59abb8
2 changed files with 43 additions and 1 deletions

View File

@ -36,7 +36,8 @@ import {
replaceAllAPIKeys, replaceAllAPIKeys,
isFlowValidForStream, isFlowValidForStream,
isVectorStoreFaiss, isVectorStoreFaiss,
databaseEntities databaseEntities,
getApiKey
} from './utils' } from './utils'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import { getDataSource } from './DataSource' import { getDataSource } from './DataSource'
@ -177,6 +178,24 @@ export class App {
return res.json(chatflows) return res.json(chatflows)
}) })
// Get specific chatflow via api key
this.app.get('/api/v1/chatflows/apikey/:apiKey', async (req: Request, res: Response) => {
try {
const apiKey = await getApiKey(req.params.apiKey)
if (!apiKey) return res.status(401).send('Unauthorized')
const chatflows = await this.AppDataSource.getRepository(ChatFlow)
.createQueryBuilder('cf')
.where('cf.apikeyid = :apikeyid', { apikeyid: apiKey.id })
.orWhere('cf.apikeyid IS NULL')
.orderBy('cf.name', 'ASC')
.getMany()
if (chatflows.length >= 1) return res.status(200).send(chatflows)
return res.status(404).send('Chatflow not found')
} catch (err: any) {
return res.status(500).send(err?.message)
}
})
// Get specific chatflow via id // Get specific chatflow via id
this.app.get('/api/v1/chatflows/:id', async (req: Request, res: Response) => { this.app.get('/api/v1/chatflows/:id', async (req: Request, res: Response) => {
const chatflow = await this.AppDataSource.getRepository(ChatFlow).findOneBy({ const chatflow = await this.AppDataSource.getRepository(ChatFlow).findOneBy({
@ -472,6 +491,17 @@ export class App {
return res.json(keys) return res.json(keys)
}) })
// Verify api key
this.app.get('/api/v1/apikey/:apiKey', async (req: Request, res: Response) => {
try {
const apiKey = await getApiKey(req.params.apiKey)
if (!apiKey) return res.status(401).send('Unauthorized')
return res.status(200).send('OK')
} catch (err: any) {
return res.status(500).send(err?.message)
}
})
// ---------------------------------------- // ----------------------------------------
// Serve UI static // Serve UI static
// ---------------------------------------- // ----------------------------------------

View File

@ -547,6 +547,18 @@ export const addAPIKey = async (keyName: string): Promise<ICommonObject[]> => {
return content return content
} }
/**
* Get API Key details
* @param {string} apiKey
* @returns {Promise<ICommonObject[]>}
*/
export const getApiKey = async (apiKey: string) => {
const existingAPIKeys = await getAPIKeys()
const keyIndex = existingAPIKeys.findIndex((key) => key.apiKey === apiKey)
if (keyIndex < 0) return undefined
return existingAPIKeys[keyIndex]
}
/** /**
* Update existing API key * Update existing API key
* @param {string} keyIdToUpdate * @param {string} keyIdToUpdate