createContact
This interface is invoked whenever a new contact needs to be created in the target CRM. This happens when a user of App Connect has elected to create a "placeholder contact."
This function is to create a placeholder contact, ONLY in the following case: * User adds a new call/message log against a number with no matched contact. In another words, create placeholder contact is tied to call/message logging action
Manifest elements
Every CRM can define a different set of contact types, or data elements that can be associated with an activity (call or SMS) log. Within the platforms.[crm name]
section of your manifest, provide the list of contact types supported by the target CRM.
..snip..
"contactTypes": [
{
"display": "TestContactType",
"value": "testContact"
},
{
"display": "Contact",
"value": "cta"
}
],
..snip..
Request parameters
Parameter | Description |
---|---|
user |
An object describing the Chrome extension user associated with the action that triggered this interface. |
authHeader |
The HTTP Authorization header to be transmitted with the API request to the target CRM. |
phoneNumber |
The phone number of the contact in E.164 format, e.g. +1231231234. |
newContactName |
The name of the contact as entered by the user. |
newContactType |
The contact type the user selected to indicate what kind of contact to create. |
Return value(s)
This interface returns a single object. That object describes the contact that was created. It has following properties:
Parameter | Description |
---|---|
contactInfo |
Contain id and name |
returnMessage |
message , messageType and ttl |
Example
{
contactInfo:{
id: "xxxx-xxxxx", // ID of the contact in the target
name: "John Doe" // Display name of the contact. This name will appear and be associated with all users with the same `phoneNumber`.
},
returnMessage:{
message: 'Contact created',
messageType: 'success', // 'success', 'warning' or 'danger'
ttl: 30000 // in miliseconds
}
}
Reference
async function createContact({ user, authHeader, phoneNumber, newContactName, newContactType }) {
// ----------------------------------------
// ---TODO.9: Implement contact creation---
// ----------------------------------------
const postBody = {
name: newContactName,
type: newContactType,
phone_numbers: [
{
name: "Work",
number: phoneNumber,
default_number: true
}
]
}
// const contactInfoRes = await axios.post(
// `https://api.crm.com/contacts`,
// postBody,
// {
// headers: { 'Authorization': authHeader }
// }
// );
mockContact = {
id: 'testContactId',
name: newContactName,
type: newContactType,
phone: phoneNumber,
additionalInfo: {
associatedDeal: [
{
const: 'csA351',
title: 'Christmas special A351'
},
{
const: 'eA22',
title: 'Easter A22'
},
{
const: 'aC92',
title: 'Anniversary C92'
}
],
address: ''
}
}
const contactInfoRes = {
data: {
id: mockContact.id,
name: mockContact.name
}
}
//--------------------------------------------------------------------------------
//---CHECK.9: In extension, try create a new contact against an unknown number ---
//--------------------------------------------------------------------------------
return {
contactInfo: {
id: contactInfoRes.id,
name: contactInfoRes.name
},
returnMessage: {
message: `Contact created.`,
messageType: 'success',
ttl: 2000
}
}
}
};
}
async function findContactWithName({ user, authHeader, name }) {
let extraDataTracking = {};
const personInfo = await axios.get(
`https://${user.hostname}/api/v2/persons/search?term=${name}&fields=name`,
{
headers: { 'Authorization': authHeader }
});
extraDataTracking = {
ratelimitRemaining: personInfo.headers['x-ratelimit-remaining'],
ratelimitAmount: personInfo.headers['x-ratelimit-limit'],
ratelimitReset: personInfo.headers['x-ratelimit-reset']
};
const matchedContactInfo = [];
for (const person of personInfo.data.data.items) {
console.log({ Item: person.item })
const dealsResponse = await axios.get(
`https://${user.hostname}/api/v2/deals?person_id=${person.item.id}&&status=open`,
{
headers: { 'Authorization': authHeader }
});
extraDataTracking = {
ratelimitRemaining: dealsResponse.headers['x-ratelimit-remaining'],
ratelimitAmount: dealsResponse.headers['x-ratelimit-limit'],
ratelimitReset: dealsResponse.headers['x-ratelimit-reset']
};
const relatedDeals = dealsResponse.data.data ?
dealsResponse.data.data.map(d => { return { const: d.id, title: d.title } })