mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Update to latest intercom client
This commit is contained in:
parent
cadccfc7e1
commit
505f888e37
6 changed files with 29 additions and 47 deletions
|
|
@ -60,17 +60,13 @@ export class CreateIntercomAccount
|
|||
const customAttributes: { source_user_id: string } = {
|
||||
source_user_id: profile.user.sourceUserId,
|
||||
}
|
||||
await IntercomClient?.users.create({
|
||||
await IntercomClient?.contacts.createUser({
|
||||
email: profile.user.email,
|
||||
user_id: profile.user.id,
|
||||
externalId: profile.user.id,
|
||||
name: profile.user.name,
|
||||
avatar: {
|
||||
image_url: profile.pictureUrl || null,
|
||||
type: 'avatar',
|
||||
},
|
||||
custom_attributes: customAttributes,
|
||||
created_at: Math.floor(new Date(profile.user.createdAt).getTime() / 1000),
|
||||
signed_up_at: Math.floor(Date.now() / 1000),
|
||||
avatar: profile.pictureUrl,
|
||||
customAttributes: customAttributes,
|
||||
signedUpAt: Math.floor(Date.now() / 1000),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ export const createArticleResolver = authorized<
|
|||
env: env.server.apiEnv,
|
||||
},
|
||||
})
|
||||
createIntercomEvent('link-saved', uid)
|
||||
await createIntercomEvent('link-saved', uid)
|
||||
|
||||
const articleSavingRequest = articleSavingRequestId
|
||||
? (await models.articleSavingRequest.get(articleSavingRequestId)) ||
|
||||
|
|
@ -507,7 +507,7 @@ export const getArticleResolver: ResolverFn<
|
|||
env: env.server.apiEnv,
|
||||
},
|
||||
})
|
||||
createIntercomEvent('get-article', claims.uid)
|
||||
await createIntercomEvent('get-article', claims.uid)
|
||||
|
||||
const article = await models.userArticle.getByUserIdAndSlug(
|
||||
claims.uid,
|
||||
|
|
@ -555,7 +555,7 @@ export const getArticlesResolver = authorized<
|
|||
env: env.server.apiEnv,
|
||||
},
|
||||
})
|
||||
createIntercomEvent('search', claims.uid)
|
||||
await createIntercomEvent('search', claims.uid)
|
||||
|
||||
const [userArticles, totalCount] = (await authTrx((tx) =>
|
||||
models.userArticle.getPaginated(
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export const createArticleSavingRequestResolver = authorized<
|
|||
CreateArticleSavingRequestError,
|
||||
MutationCreateArticleSavingRequestArgs
|
||||
>(async (_, { input: { url } }, { models, claims }) => {
|
||||
createIntercomEvent('link-save-request', claims.uid)
|
||||
await createIntercomEvent('link-save-request', claims.uid)
|
||||
const request = await createPageSaveRequest(claims.uid, url, models)
|
||||
return {
|
||||
articleSavingRequest: request,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export const savePageResolver = authorized<
|
|||
models,
|
||||
claims: { uid },
|
||||
} = ctx
|
||||
createIntercomEvent('link-saved', uid)
|
||||
await createIntercomEvent('link-saved', uid)
|
||||
|
||||
const user = userDataToUser(await models.user.get(uid))
|
||||
if (!user) {
|
||||
|
|
@ -44,7 +44,7 @@ export const saveUrlResolver = authorized<
|
|||
models,
|
||||
claims: { uid },
|
||||
} = ctx
|
||||
createIntercomEvent('link-saved', uid)
|
||||
await createIntercomEvent('link-saved', uid)
|
||||
|
||||
const user = userDataToUser(await models.user.get(uid))
|
||||
if (!user) {
|
||||
|
|
@ -63,7 +63,7 @@ export const saveFileResolver = authorized<
|
|||
models,
|
||||
claims: { uid },
|
||||
} = ctx
|
||||
createIntercomEvent('link-saved', uid)
|
||||
await createIntercomEvent('link-saved', uid)
|
||||
|
||||
const user = userDataToUser(await models.user.get(uid))
|
||||
if (!user) {
|
||||
|
|
|
|||
|
|
@ -333,13 +333,11 @@ export function authRouter() {
|
|||
|
||||
if (env.server.apiEnv && !env.dev.isLocal && IntercomClient) {
|
||||
if (newUser) {
|
||||
createIntercomEvent('signed-up', user.id, function () {
|
||||
redirect(res)
|
||||
})
|
||||
await createIntercomEvent('signed-up', user.id)
|
||||
redirect(res)
|
||||
} else {
|
||||
createIntercomEvent('logged-in', user.id, function () {
|
||||
redirect(res)
|
||||
})
|
||||
await createIntercomEvent('logged-in', user.id)
|
||||
redirect(res)
|
||||
}
|
||||
} else {
|
||||
redirect(res)
|
||||
|
|
|
|||
|
|
@ -1,35 +1,23 @@
|
|||
import * as Intercom from 'intercom-client'
|
||||
import { Client } from 'intercom-client'
|
||||
import { env } from '../env'
|
||||
|
||||
export const IntercomClient =
|
||||
env.server.apiEnv && !env.dev.isLocal
|
||||
? new Intercom.Client({
|
||||
token: env.intercom.token,
|
||||
? new Client({
|
||||
tokenAuth: { token: env.intercom.token },
|
||||
})
|
||||
: null
|
||||
|
||||
IntercomClient?.useRequestOpts({
|
||||
headers: {
|
||||
'Intercom-Version': 1.4,
|
||||
},
|
||||
})
|
||||
|
||||
export function createIntercomEvent(
|
||||
export async function createIntercomEvent(
|
||||
eventName: string,
|
||||
userId: string,
|
||||
callback?: () => void
|
||||
): void {
|
||||
if (!callback) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
callback = () => {}
|
||||
userId: string
|
||||
): Promise<void> {
|
||||
if (!IntercomClient) {
|
||||
return
|
||||
}
|
||||
if (!IntercomClient) return callback()
|
||||
IntercomClient.events.create(
|
||||
{
|
||||
event_name: eventName,
|
||||
user_id: userId,
|
||||
created_at: Math.floor(Date.now() / 1000), // this is mandatory for events
|
||||
},
|
||||
callback
|
||||
)
|
||||
return IntercomClient.events.create({
|
||||
eventName: eventName,
|
||||
userId: userId,
|
||||
createdAt: Math.floor(Date.now() / 1000), // this is mandatory for events
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue