kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: refactor signature and add tests
rodzic
32e971f4a2
commit
3e69080fdf
|
@ -34,24 +34,27 @@ export class NovuClient {
|
|||
this.baseUrl = baseUrl
|
||||
}
|
||||
|
||||
async triggerEvent(
|
||||
name: string,
|
||||
payload: Record<string, unknown>,
|
||||
async triggerEvent({
|
||||
name,
|
||||
payload,
|
||||
to
|
||||
}: {
|
||||
name: string
|
||||
payload: Record<string, unknown>
|
||||
to: NovuSubscriber[]
|
||||
) {
|
||||
}) {
|
||||
const url = `${this.baseUrl}/events/trigger`
|
||||
const headers = {
|
||||
Authorization: `ApiKey ${this.apiKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
const body = JSON.stringify({
|
||||
name,
|
||||
payload,
|
||||
to
|
||||
})
|
||||
const response = await ky.post(url, {
|
||||
headers,
|
||||
body
|
||||
json: {
|
||||
name,
|
||||
payload,
|
||||
to
|
||||
}
|
||||
})
|
||||
return response.json<NovuTriggerEventResponse>()
|
||||
}
|
||||
|
|
|
@ -69,11 +69,7 @@ export class NovuNotificationTool extends BaseTask<
|
|||
// TODO: handle errors gracefully
|
||||
input = this.inputSchema.parse(input)
|
||||
|
||||
const result = await this._novuClient.triggerEvent(
|
||||
input.name,
|
||||
input.payload,
|
||||
input.to
|
||||
)
|
||||
const result = await this._novuClient.triggerEvent(input)
|
||||
return {
|
||||
result,
|
||||
metadata: {}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import test from 'ava'
|
||||
|
||||
import { NovuClient } from '../src/services/novu'
|
||||
import './_utils'
|
||||
|
||||
test('NovuClient.triggerEvent', async (t) => {
|
||||
if (!process.env.NOVU_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new NovuClient()
|
||||
|
||||
const result = await client.triggerEvent({
|
||||
name: 'send-email',
|
||||
payload: {
|
||||
content: 'Hello World!'
|
||||
},
|
||||
to: [
|
||||
{
|
||||
subscriberId: '123456',
|
||||
email: 'pburckhardt@outlook.com'
|
||||
}
|
||||
]
|
||||
})
|
||||
t.truthy(result)
|
||||
})
|
Ładowanie…
Reference in New Issue