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
// });
console.log(`update message log with... \n\n${JSON.stringify(message, null, 2)}`);
//---------------------------------------------------------------------------------------------------------------------------------------------
//---CHECK.8: For multiple messages or additional message during the day, open db.sqlite and CRM website to check if message logs are saved ---
//---------------------------------------------------------------------------------------------------------------------------------------------
}
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
phone: rawContactInfo.phones[0],
organization: rawContactInfo.organization?.name ?? '',
additionalInfo: relatedDeals ? { deals: relatedDeals } : null
}
}
async function createContact({ user, authHeader, phoneNumber, newContactName }) {
const postBody = {
name: newContactName,
phone: phoneNumber
}
const createContactRes = await axios.post(
`https://${user.hostname}/v1/persons`,
postBody,
{
headers: { 'Authorization': authHeader }
});
return {
contactInfo: {
id: createContactRes.data.data.id,
name: createContactRes.data.data.name
},