Skip to content

Commit

Permalink
added get contact details flow node
Browse files Browse the repository at this point in the history
  • Loading branch information
alexteusz committed Jul 6, 2023
1 parent 40b25fa commit 49f52df
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 16 deletions.
3 changes: 2 additions & 1 deletion extensions/zendesk-sell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ All exposed Flow Nodes of this Extension follow the [Zendesk Sales CRM API](http

### Exposed Nodes

- [Search](https://developer.zendesk.com/api-reference/sales-crm/search/introduction/)
- [Search Contacts](https://developer.zendesk.com/api-reference/sales-crm/search/introduction/)
- [Get Contact Details](https://developer.zendesk.com/api-reference/sales-crm/resources/contacts/#retrieve-a-single-contact)
5 changes: 4 additions & 1 deletion extensions/zendesk-sell/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { createExtension } from "@cognigy/extension-tools";
import { zendeskSellOAuth2AccessTokenConnection } from "./connections/zendeskSellOAuth2AccessTokenConnection";
import { onFoundContacts, onNotFoundContacts, searchContactsNode } from "./nodes/search";
import { getContactDetailsNode } from "./nodes/getContactDetails";



export default createExtension({
nodes: [
searchContactsNode,
onFoundContacts,
onNotFoundContacts
onNotFoundContacts,

getContactDetailsNode
],

connections: [
Expand Down
158 changes: 158 additions & 0 deletions extensions/zendesk-sell/src/nodes/getContactDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { createNodeDescriptor, INodeFunctionBaseParams } from "@cognigy/extension-tools";
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";

export interface IGetContactDetailsParams extends INodeFunctionBaseParams {
config: {
connection: {
accessToken: string;
};
contactId: string;
storeLocation: string;
contextKey: string;
inputKey: string;
};
}
export const getContactDetailsNode = createNodeDescriptor({
type: "getContactDetails",
defaultLabel: {
default: "Get Contact Details",
deDE: "Erhalte Kontakt"
},
summary: {
default: "Returns the details of a given contact by id",
deDE: "Gibt die Details einens Kontaktes anhand der ID zurück",
},
fields: [
{
key: "connection",
label: {
default: "Zendesk Sell Connection",
deDE: "Zendesk Sell Verbindung"
},
type: "connection",
params: {
connectionType: "zendesk-sell-access-token",
required: true
}
},

{
key: "contactId",
label: {
default: "Contact ID",
deDE: "Kontakt ID"
},
type: "cognigyText",
defaultValue: "{{input.zendesk.contacts[0].items[0].data.id}}",
params: {
required: true,
}
},
{
key: "storeLocation",
type: "select",
label: {
default: "Where to store the result",
deDE: "Wo das Ergebnis gespeichert werden soll"
},
defaultValue: "input",
params: {
options: [
{
label: "Input",
value: "input"
},
{
label: "Context",
value: "context"
}
],
required: true
},
},
{
key: "inputKey",
type: "cognigyText",
label: {
default: "Input Key to store Result",
deDE: "Input Key zum Speichern des Ergebnisses",
},
defaultValue: "zendesk.contact",
condition: {
key: "storeLocation",
value: "input",
}
},
{
key: "contextKey",
type: "cognigyText",
label: {
default: "Context Key to store Result",
deDE: "Context Key zum Speichern des Ergebnisses",
},
defaultValue: "zendesk.contact",
condition: {
key: "storeLocation",
value: "context",
}
},
],
sections: [
{
key: "storage",
label: {
default: "Storage Option",
deDE: "Speicheroption",
},
defaultCollapsed: true,
fields: [
"storeLocation",
"inputKey",
"contextKey",
]
}
],
form: [
{ type: "field", key: "connection" },
{ type: "field", key: "contactId" },
{ type: "section", key: "storage" },
],
appearance: {
color: "#D4AE5E"
},
function: async ({ cognigy, config }: IGetContactDetailsParams) => {
const { api } = cognigy;
const { contactId, connection, storeLocation, contextKey, inputKey } = config;
const { accessToken } = connection;

try {

const response = await axios({
method: "get",
url: `https://api.getbase.com/v2/contacts/${contactId}`,
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": `Bearer ${accessToken}`
}
});

if (storeLocation === "context") {
api.addToContext(contextKey, response?.data?.data, "simple");
} else {
// @ts-ignore
api.addToInput(inputKey, response?.data?.data);
}

} catch (error) {

if (storeLocation === "context") {
api.addToContext(contextKey, { error: error }, "simple");
} else {
// @ts-ignore
api.addToInput(inputKey, { error: error });
}
}

}
});
24 changes: 10 additions & 14 deletions extensions/zendesk-sell/src/nodes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ export const searchContactsNode = createNodeDescriptor({
{
key: "mobile",
label: {
default: "Full Name",
deDE: "Name"
default: "Mobile Number",
deDE: "Handynummer"
},
type: "cognigyText",
params: {
Expand Down Expand Up @@ -219,7 +219,6 @@ export const searchContactsNode = createNodeDescriptor({
label: {
default: "Storage Option",
deDE: "Speicheroption",
esES: "Opción de almacenamiento"
},
defaultCollapsed: true,
fields: [
Expand Down Expand Up @@ -249,6 +248,13 @@ export const searchContactsNode = createNodeDescriptor({
"onNotFoundContacts"
]
},
tokens: [
{
label: "First Found Contact ID",
script: "input.zendesk.contacts[0].items[0].data.id",
type: "input"
}
],
function: async ({ cognigy, config, childConfigs }: ISearchContactsParams) => {
const { api } = cognigy;
const { filterOperator, useMobile, useEmail, useDisplayName, mobile, email, displayName, connection, storeLocation, contextKey, inputKey } = config;
Expand All @@ -260,7 +266,7 @@ export const searchContactsNode = createNodeDescriptor({
filters.push({
"filter": {
"attribute": {
"name": "mobile"
"name": "phone_numbers.mobile"
},
"parameter": {
"starts_with": mobile
Expand Down Expand Up @@ -327,16 +333,6 @@ export const searchContactsNode = createNodeDescriptor({
api.setNextNode(onErrorChild.id);
} else {

const contactResponse = await axios({
method: "get",
url: `https://api.getbase.com/v2/contacts/${response.data.items[0]items[0].data.id}`,
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": `Bearer ${accessToken}`
}
});

const onSuccessChild = childConfigs.find(child => child.type === "onFoundContacts");
api.setNextNode(onSuccessChild.id);

Expand Down

0 comments on commit 49f52df

Please sign in to comment.