Skip to content

Commit

Permalink
fix(intercom): update syncs and actions (#106)
Browse files Browse the repository at this point in the history
## Describe your changes
Clean up intercom syncs and actions

## Issue ticket number and link

## Checklist before requesting a review (skip if just adding/editing
APIs & templates)
- [x] I added tests, otherwise the reason is:
- [ ] External API requests have `retries`
- [x] Pagination is used where appropriate
- [x] The built in `nango.paginate` call is used instead of a `while
(true)` loop
- [ ] Third party requests are NOT parallelized (this can cause issues
with rate limits)
- [ ] If a sync requires metadata the `nango.yaml` has `auto_start:
false`
- [ ] If the sync is a `full` sync then `track_deletes: true` is set
- [ ] I followed the best practices and guidelines from the [Writing
Integration
Scripts](/NangoHQ/integration-templates/blob/main/WRITING_INTEGRATION_SCRIPTS.md)
doc
  • Loading branch information
khaliqgant authored Nov 12, 2024
1 parent 8f74f8f commit 1d44fff
Show file tree
Hide file tree
Showing 30 changed files with 440 additions and 900 deletions.
22 changes: 11 additions & 11 deletions flows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4221,14 +4221,14 @@ integrations:
input: IdEntity
endpoint: GET /single-article
output: Article
create-user:
description: Creates a user in Intercom
input: IntercomCreateUser
endpoint: POST /users
output: User
delete-user:
description: Deletes a user in Intercom
endpoint: DELETE /users
create-contact:
description: Creates a contact in Intercom
input: IntercomCreateContact
endpoint: POST /contact
output: Contact
delete-contact:
description: Deletes a contact in Intercom
endpoint: DELETE /contact
output: SuccessResponse
input: IdEntity
syncs:
Expand Down Expand Up @@ -4265,7 +4265,7 @@ integrations:
users:
runs: every 6 hours
description: |
Fetches a list of users from Intercom
Fetches a list of admin users from Intercom
output: User
sync_type: incremental
endpoint: GET /users
Expand Down Expand Up @@ -4381,11 +4381,11 @@ integrations:
email: string
firstName: string
lastName: string
CreateUser:
CreateContact:
firstName: string
lastName: string
email: string
IntercomCreateUser:
IntercomCreateContact:
firstName: string
lastName: string
email: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NangoAction, ProxyConfiguration, User, IntercomCreateUser } from '../../models';
import { toUser } from '../mappers/to-user.js';
import { intercomCreateUserSchema } from '../schema.zod.js';
import type { NangoAction, ProxyConfiguration, Contact, IntercomCreateContact } from '../../models';
import { toContact } from '../mappers/to-contact.js';
import { intercomCreateContactSchema } from '../schema.zod.js';
import type { IntercomContact } from '../types';

/**
Expand All @@ -11,25 +11,25 @@ import type { IntercomContact } from '../types';
* errors and throws an ActionError.
*
* @param {NangoAction} nango - The Nango action context, used for logging and making API requests.
* @param {IntercomCreateUser} input - The input data for creating a user contact
* @param {IntercomCreateContact} input - The input data for creating a contact
*
* @returns {Promise<User>} - A promise that resolves to the created User object.
* @returns {Promise<Contact>} - A promise that resolves to the created contact object.
*
* @throws {nango.ActionError} - Throws an error if the input validation fails.
*
* For detailed endpoint documentation, refer to:
* https://developers.intercom.com/docs/references/rest-api/api.intercom.io/contacts/createcontact
*/
export default async function runAction(nango: NangoAction, input: IntercomCreateUser): Promise<User> {
const parsedInput = intercomCreateUserSchema.safeParse(input);
export default async function runAction(nango: NangoAction, input: IntercomCreateContact): Promise<Contact> {
const parsedInput = intercomCreateContactSchema.safeParse(input);

if (!parsedInput.success) {
for (const error of parsedInput.error.errors) {
await nango.log(`Invalid input provided to create a user: ${error.message} at path ${error.path.join('.')}`, { level: 'error' });
await nango.log(`Invalid input provided to create a contact: ${error.message} at path ${error.path.join('.')}`, { level: 'error' });
}

throw new nango.ActionError({
message: 'Invalid input provided to create a user'
message: 'Invalid input provided to create a contact'
});
}

Expand All @@ -48,5 +48,5 @@ export default async function runAction(nango: NangoAction, input: IntercomCreat

const response = await nango.post<IntercomContact>(config);

return toUser(response.data);
return toContact(response.data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { idEntitySchema } from '../schema.zod.js';
import type { IntercomDeleteContactResponse } from '../types';

/**
* Deletes an Intercom user contact.
* Deletes an Intercom contact.
*
* This function validates the input against the defined schema and constructs a request
* to the Intercom API to delete a user contact by their ID. If the input is invalid,
* to the Intercom API to delete a contact by their ID. If the input is invalid,
* it logs the errors and throws an ActionError.
*
* @param {NangoAction} nango - The Nango action context, used for logging and making API requests.
* @param {IdEntity} input - The input data containing the ID of the user contact to be deleted
* @param {IdEntity} input - The input data containing the ID of the contact to be deleted
*
* @returns {Promise<SuccessResponse>} - A promise that resolves to a SuccessResponse object indicating the result of the deletion.
*
Expand All @@ -24,11 +24,11 @@ export default async function runAction(nango: NangoAction, input: IdEntity): Pr

if (!parsedInput.success) {
for (const error of parsedInput.error.errors) {
await nango.log(`Invalid input provided to delete a user: ${error.message} at path ${error.path.join('.')}`, { level: 'error' });
await nango.log(`Invalid input provided to delete a contact: ${error.message} at path ${error.path.join('.')}`, { level: 'error' });
}

throw new nango.ActionError({
message: 'Invalid input provided to delete a user'
message: 'Invalid input provided to delete a contact'
});
}

Expand Down
4 changes: 2 additions & 2 deletions integrations/intercom/mappers/to-user.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { User } from '../../models';
import type { IntercomContact } from '../types';
import type { IntercomContact, IntercomAdminUser } from '../types';

/**
* Maps an Intercom API contact object to a Nango User object.
*
* @param contact The raw contact object from the Intercom API.
* @returns Mapped User object with essential properties.
*/
export function toUser(contact: IntercomContact): User {
export function toUser(contact: IntercomContact | IntercomAdminUser): User {
const [firstName = '', lastName = ''] = (contact?.name ?? '').split(' ');

return {
Expand Down
79 changes: 7 additions & 72 deletions integrations/intercom/mocks/contacts/Contact/batchSave.json
Original file line number Diff line number Diff line change
@@ -1,80 +1,15 @@
[
{
"id": "66f7ee5ea9e2c41564b4c362",
"workspace_id": "s0lour9i",
"external_id": "3892ec77-2638-4343-a883-54c1ead2e35e",
"id": "67327549c52835a6025fe1c1",
"workspace_id": "aiiw21up",
"external_id": "ab734fed-c8bd-43b5-9c83-284956478296",
"type": "user",
"email": "example.user@projectmap.com",
"phone": null,
"name": "Example User",
"created_at": "2024-09-28T11:54:06.000Z",
"updated_at": "2024-09-28T11:54:25.000Z",
"last_seen_at": "2024-09-28T11:54:06.000Z",
"last_replied_at": "2024-09-28T11:54:23.000Z"
},
{
"id": "66fadfecea421c7b5057f6f0",
"workspace_id": "s0lour9i",
"external_id": "1234566",
"type": "user",
"email": "john.doe@example.com",
"phone": null,
"name": "John Doe",
"created_at": "2024-09-30T17:29:16.000Z",
"updated_at": "2024-09-30T17:29:16.000Z",
"last_seen_at": null,
"last_replied_at": null
},
{
"id": "66fae008c39645865b3c0443",
"workspace_id": "s0lour9i",
"external_id": "23477",
"type": "user",
"email": "james@test.com",
"phone": null,
"name": "James Test",
"created_at": "2024-09-30T17:29:44.000Z",
"updated_at": "2024-09-30T17:29:44.000Z",
"last_seen_at": null,
"last_replied_at": null
},
{
"id": "66fae01ac4f9bc7fb131a4a6",
"workspace_id": "s0lour9i",
"external_id": "894343",
"type": "user",
"email": "test@test.com",
"phone": null,
"name": null,
"created_at": "2024-09-30T17:30:02.000Z",
"updated_at": "2024-09-30T17:30:02.000Z",
"last_seen_at": null,
"last_replied_at": null
},
{
"id": "66fae0386198fdb3ae7e8746",
"workspace_id": "s0lour9i",
"external_id": "4353453",
"type": "user",
"email": "test@tes2t.com",
"phone": null,
"name": "Ian Test",
"created_at": "2024-09-30T17:30:33.000Z",
"updated_at": "2024-09-30T17:30:33.000Z",
"last_seen_at": null,
"last_replied_at": null
},
{
"id": "66fae05c6a8ee5104e5c6ee1",
"workspace_id": "s0lour9i",
"external_id": "324343",
"type": "user",
"email": "phil@inter.com",
"phone": null,
"name": "Phil Intercom",
"created_at": "2024-09-30T17:31:08.000Z",
"updated_at": "2024-09-30T17:31:08.000Z",
"last_seen_at": null,
"last_replied_at": null
"created_at": "2024-11-11T21:21:13.000Z",
"updated_at": "2024-11-11T21:21:34.000Z",
"last_seen_at": "2024-11-11T21:21:13.000Z",
"last_replied_at": "2024-11-11T21:21:32.000Z"
}
]
5 changes: 5 additions & 0 deletions integrations/intercom/mocks/create-contact/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"email": "foo@goo.com",
"firstName": "Foo",
"lastName": "Bryant"
}
13 changes: 13 additions & 0 deletions integrations/intercom/mocks/create-contact/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": "67331e9ead6af79f49321675",
"workspace_id": "aiiw21up",
"external_id": null,
"type": "user",
"email": "foo@goo.com",
"phone": null,
"name": "Foo Bryant",
"created_at": "2024-11-12T09:23:42.000Z",
"updated_at": "2024-11-12T09:23:42.000Z",
"last_seen_at": null,
"last_replied_at": null
}
5 changes: 0 additions & 5 deletions integrations/intercom/mocks/create-user/input.json

This file was deleted.

6 changes: 0 additions & 6 deletions integrations/intercom/mocks/create-user/output.json

This file was deleted.

3 changes: 3 additions & 0 deletions integrations/intercom/mocks/delete-contact/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "67331e9ead6af79f49321675"
}
3 changes: 0 additions & 3 deletions integrations/intercom/mocks/delete-user/input.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "67331e9ead6af79f49321675",
"external_id": null,
"type": "contact",
"deleted": true
}
27 changes: 27 additions & 0 deletions integrations/intercom/mocks/nango/get/proxy/admins/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "admin.list",
"admins": [
{
"type": "admin",
"email": "khaliq@nango.dev",
"id": "7890376",
"name": "Khaliq Gant",
"away_mode_enabled": false,
"away_mode_reassign": false,
"has_inbox_seat": true,
"team_ids": [],
"team_priority_level": {}
},
{
"type": "admin",
"email": "operator+aiiw21up@intercom.io",
"id": "7890377",
"name": "Fin",
"away_mode_enabled": false,
"away_mode_reassign": false,
"has_inbox_seat": true,
"team_ids": [],
"team_priority_level": {}
}
]
}
Loading

0 comments on commit 1d44fff

Please sign in to comment.