omnivore/packages/api/src/utils/intercom.ts

24 lines
542 B
TypeScript
Raw Normal View History

2022-03-01 19:20:31 +00:00
import { Client } from 'intercom-client'
2022-02-11 17:24:33 +00:00
import { env } from '../env'
export const IntercomClient =
env.server.apiEnv && !env.dev.isLocal
2022-03-01 19:20:31 +00:00
? new Client({
tokenAuth: { token: env.intercom.token },
2022-02-11 17:24:33 +00:00
})
: null
2022-03-01 19:20:31 +00:00
export async function createIntercomEvent(
2022-02-11 17:24:33 +00:00
eventName: string,
2022-03-01 19:20:31 +00:00
userId: string
): Promise<void> {
if (!IntercomClient) {
return
2022-02-11 17:24:33 +00:00
}
2022-03-01 19:20:31 +00:00
return IntercomClient.events.create({
eventName: eventName,
userId: userId,
createdAt: Math.floor(Date.now() / 1000), // this is mandatory for events
})
2022-02-11 17:24:33 +00:00
}