Skip to content

Feature/attio #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ env:
MAILCHIMP_TOKEN: ${{ secrets.MAILCHIMP_TOKEN }}
MAILCHIMP_DATACENTER: ${{ secrets.MAILCHIMP_DATACENTER }}
INTERCOM_TOKEN: ${{ secrets.INTERCOM_TOKEN }}
ATTIO_TOKEN: ${{ secrets.ATTIO_TOKEN }}

jobs:
PullRequestTests:
Expand Down
2 changes: 1 addition & 1 deletion ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@microsoft/microsoft-graph-types": "^2.40.0",
"@notionhq/client": "^2.2.15",
"@octokit/rest": "18.12.0",
"@qoretechnologies/ts-toolkit": "^0.5.27",
"@qoretechnologies/ts-toolkit": "^0.5.32",
"@shopify/admin-api-client": "^1.0.7",
"@sinclair/typebox": "^0.33.0",
"@slack/web-api": "^7.3.2",
Expand Down
2 changes: 2 additions & 0 deletions ts/src/ActionsCatalogue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import mailchimp from '../apps/mailchimp';
import dynamics from '../apps/dynamics';
import xero from '../apps/xero';
import intercom from '../apps/intercom';
import attio from '../apps/attio';

if (process.env.TS_DEBUG) {
Debugger.level = DebugLevels.Verbose;
Expand Down Expand Up @@ -68,6 +69,7 @@ const NEW_APPS = {
mailchimp,
xero,
intercom,
attio,
} as const;

const EXISTING_APPS = {
Expand Down
128 changes: 128 additions & 0 deletions ts/src/apps/attio/actions/create-list-entry.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import {
EQoreAppActionCode,
QoreAppCreator,
QorusRequest,
TQoreOptions,
} from '@qoretechnologies/ts-toolkit';
import { ATTIO_APP_API_URL, ATTIO_APP_NAME, AttioError } from '../constants';
import { formatAttioResponse } from '../helpers/format-response';
import { getAttioListApiSlugAllowedValues } from '../helpers/get-list-allowed-values';
import { getAttioAttributesAsQoreOptions } from '../helpers/get-object-properties';
import { getAttioListParentRecordIdAllowedValues } from '../helpers/get-list-parent-record-id-allowed-values';
import { getListParentObjectDefaultValue } from '../helpers/get-list-parent-object-default-value';
import { getQoreContextRequiredValues } from '../../../global/helpers';
import { getAttioResponseType } from '../helpers/get-response-type';

const options = {
list: {
required: true,
type: 'string',
get_allowed_values: getAttioListApiSlugAllowedValues,
on_change: ['refetch'],
get_dependent_options: async (context) => {
const list = context?.opts?.list;
const token = context?.conn_opts?.token;

if (!list)
return {
attributes: {
required: true,
type: 'hash',
},
};

const attributes = await getAttioAttributesAsQoreOptions('lists', list, token!);

return {
attributes: {
required: true,
type: {
type: 'hash',
fields: attributes,
},
},
};
},
},
parent_record_id: {
type: 'string',
required: true,
get_allowed_values: getAttioListParentRecordIdAllowedValues,
},
} satisfies TQoreOptions;

const additionalOptions = {
attributes: {
type: 'hash',
required: false,
preselected: true,
},
} satisfies TQoreOptions;

const createAttioListEntry = QoreAppCreator.createLocalizedAction<
typeof options & Partial<typeof additionalOptions>
>({
app: ATTIO_APP_NAME,
action: 'create_list_entry',
action_code: EQoreAppActionCode.ACTION,
options,
api_function: async (obj, _opts, context) => {
const token = context?.conn_opts?.token;
const list = obj?.list;
const attributes = obj?.attributes || {};
const parent_record_id = obj?.parent_record_id;
const parent_object = await getListParentObjectDefaultValue({ ...context, opts: obj });

const missingValues: string[] = [];

if (!token) missingValues.push('token');
if (!list) missingValues.push('list');
if (!attributes) missingValues.push('attributes');
if (!parent_record_id) missingValues.push('parent_record_id');
if (!parent_object) missingValues.push('parent_object');

if (missingValues.length > 0) {
throw new AttioError(`Missing required values: ${missingValues.join(', ')}`);
}

try {
const response = await QorusRequest.post<{ data: any }>(
{
path: `/v2/lists/${list}/entries`,
data: {
data: {
parent_record_id,
parent_object,
entry_values: attributes,
},
},
headers: {
Authorization: `Bearer ${token}`,
},
},
{ url: ATTIO_APP_API_URL, endpointId: ATTIO_APP_NAME }
);

return formatAttioResponse(response?.data, 'lists', list!, token!);
} catch (error) {
throw new AttioError(`Failed to create list entry: ${error}`);
}
},
get_dynamic_response_type: async (context) => {
if (!context) throw new AttioError('Context is required to get dynamic response type');

const { list, token } = getQoreContextRequiredValues({
context,
optionFields: ['list'],
connectionFields: ['token'],
ErrorClass: AttioError,
});

return await getAttioResponseType({
list,
token,
});
},
});

export default createAttioListEntry;
130 changes: 130 additions & 0 deletions ts/src/apps/attio/actions/create-note.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import {
EQoreAppActionCode,
QoreAppCreator,
QorusRequest,
TQoreMappedOptions,
TQoreOptions,
} from '@qoretechnologies/ts-toolkit';
import { getQoreContextRequiredValues } from '../../../global/helpers';
import { ATTIO_APP_NAME, AttioEndpointData, AttioError } from '../constants';
import { getAttioObjectApiSlugAllowedValues } from '../helpers/get-object-allowed-values';
import { getAttioObjectRecordIdAllowedValues } from '../helpers/get-object-record-id-allowed-values';

const options = {
parent_object: {
required: true,
type: 'string',
allowed_values_creatable: true,
get_allowed_values: getAttioObjectApiSlugAllowedValues,
on_change: ['refetch'],
},
parent_record_id: {
required: true,
type: 'string',
allowed_values_creatable: true,
get_allowed_values: getAttioObjectRecordIdAllowedValues,
depends_on: ['parent_object'],
},
title: {
required: true,
type: 'string',
},
format: {
required: true,
type: 'string',
default_value: 'plaintext',
allowed_values: [
{
value: 'plaintext',
display_name: 'Plain Text',
},
{
value: 'markdown',
display_name: 'Markdown',
},
],
},
content: {
required: true,
type: 'string',
},
} satisfies TQoreOptions;

const createAttioNote = QoreAppCreator.createLocalizedAction<typeof options>({
app: ATTIO_APP_NAME,
action: 'create_note',
action_code: EQoreAppActionCode.ACTION,
options,
api_function: async (obj, _opts, context) => {
const { token, ...otherOptions } = getQoreContextRequiredValues<
TQoreMappedOptions<typeof options> & { token: string }
>({
context: { ...context, opts: obj },
optionFields: ['content', 'parent_object', 'parent_record_id', 'title', 'format'],
connectionFields: ['token'],
ErrorClass: AttioError,
});

try {
const response = await QorusRequest.post<{ data: { data: any } }>(
{
path: `/v2/notes`,
headers: {
Authorization: `Bearer ${token}`,
},
data: {
data: otherOptions,
},
},
AttioEndpointData
);

return response?.data?.data;
} catch (error) {
throw new AttioError(`Failed to create a note: ${error}`);
}
},
response_type: {
type: 'hash',
fields: {
id: {
type: {
type: 'hash',
fields: {
workspace_id: { type: 'string' },
note_id: { type: 'string' },
},
},
},
parent_object: {
type: 'string',
},
parent_record_id: {
type: 'string',
},
title: {
type: 'string',
},
content_plaintext: {
type: 'string',
},
content_markdown: {
type: 'string',
},
created_by_actor: {
type: {
type: 'hash',
fields: {
type: { type: 'string' },
id: { type: 'string' },
},
},
},
created_at: {
type: 'string',
},
},
},
});

export default createAttioNote;
Loading
Loading