# Salesforce

Salesforce is a CRM system. The internal Salesforce integration provides API access to built-in operations that you can execute between RELE.AI and Salesforce.

The purpose of the integration is to allow the user to retrieve or save information in a Salesforce account.

# Find Objects

Attribute: find_objects

Finds a Salesforce object within a salesforce account.
The function searches for salesforce object in salesforce according to each of the parameters provided under the above fields:
Email Phone FirstName LastName query

NOTE

query is a free search key, which searches by all the properties that salesforce allows you to search for.

In addition, the function gets another object called findBy.
Each key under findBy defines the type of objects we want to retrieve from salesforce. We currently support contacts / accounts.
Under each such object, we can define exactly what fields we want to retrieve, and whether our search will be based on these fields.
That is, any key defined under an object type can contain two parameters: searchBy, and location.

searchBy defines whether the search filter will execute according to this field (if the value is set to false, the field will be retrieved, but the search filter will not execute by this field).
location defines the position of the field in the array of results that will be returned from the endpoint. Can be in the range of 1 - max_int.

# find_objects is opeartion thats searches object on salesforce.
type: Operation

# define the pointers to the
# internal app & app action
selector:
    app: salesforce
    app_action: find_objects

# define the find_objects payload
payload:
    # query is a free value by which the search will be performed.
    query:
        data: crm_contact:message_data:message:body
        rkey_type: hash_map
        type: redis

    # define the find by object
    findBy:
        data:
            contacts:
                Name:
                    searchBy: true
                    location: 1
                Email:
                    searchBy: true
                    location: 2
            accounts:
                Name:
                    searchBy: true
        type: raw

# redis-key that will hold the response
# from find_objects
redis:
  field: crm_contact_info
  type: hash_map

# Create Contact

Attribute: create_contact

Create a Contact within a salesforce account.
The function create a contact in salesforce according to each of the parameters provided under the above fields:
Email Phone FirstName LastName

# create_contact is opeartion thats creates contact on salesforce.
type: Operation

# define the pointers to the
# internal app & app action
selector:
    app: salesforce
    app_action: create_contact

# define the create_contact payload
payload:
    # contact phone proprety
    Phone:
        data: check_contact_info:phone
        rkey_type: hash_map
        type: redis

    # contact firstname proprety
    FirstName:
        data: check_contact_info:firstname
        rkey_type: hash_map
        type: redis

    # contact lastname proprety
    LastName:
        data: check_contact_info:lastname
        rkey_type: hash_map
        type: redis

    # contact email proprety
    Email:
        data: check_contact_info:email
        rkey_type: hash_map
        type: redis

# redis-key that will hold the response
# from create_contact
redis:
  field: contact_response
  type: hash_map

# Get Contact Information

Attribute: get_contact_info

Get contact info takes a salesforce's contact id, and pulls information about it.
The type of information that will be retrieved depends on pullFromSalesforce array of strings, which defines what information will be returned, in addition to the details of the contact.
The array can contain three values:
account: Returns info about the account related to the contact.
contactOpportunities: Returns info about the contact's open opportunities.
accountOpportunities: Returns info about the account's open opportunities.

# get_contact_info is opeartion thats
# pulls info about contact from salesforce.
type: Operation

# define the pointers to the
# internal app & app action
selector:
    app: salesforce
    app_action: get_contact_info

# define the get_contact_info payload
payload:
    # salesforce's contact id
    id:
        data: crm_contact_info:contacts:0:vid
        rkey_type: hash_map
        type: redis

    # defines which type of info to get back
    pullFromSalesforce:
        data:
            - account
        type: raw

# redis-key that will hold the response
# from get_contact_info
redis:
  field: get_contact_info_response
  type: hash_map

# Record Note

Attribute: record_note

Record Note creates a note in a salesforce and attaches it to an object in a salesforce Record Note Gets an id of an object in a salesforce and an array of base64 messages/files to record as a body.

# record_note is opeartion thats
# create note in salesforce.
type: Operation

# define the pointers to the
# internal app & app action
selector:
    app: salesforce
    app_action: record_note

# define the record_note payload
payload:
    # salesforce's contact id
    id:
        data: get_contact_info:objects:0:vid
        rkey_type: hash_map
        type: redis

    # array of base64 messages/files
    body:
        data: messages:messages:messages_b64
        type: redis
        rkey_type: hash_map


# redis-key that will hold the response
# from record_note
redis:
  field: record_write_result
  type: hash_map

# Search Objects

Attribute: search_objects

Search objects Searches for objects in a salesforce by query.
The function gets a query that defines the search key-word, and an array of search_by that defines which objects in the salesforce the search should be performed.
search_by is an array of objects, each object defining the type of object in the salesforce that should be searched for, what properties to search by, and what properties we want to retrieve in the answer.

Each object in the array includes some attributes:
type: Defines the salesforce's object type that you want to search for.
generalProperties: Defines the properties you want to pull in your response, if there is a match.
searchByProperties: Defines the properties by which the search will be performed.

# search_objects is opeartion thats
# search for objects in salesforce.
type: Operation

# define the pointers to the
# internal app & app action
selector:
    app: salesforce
    app_action: search_objects

# define the search_objects payload
payload:
    # salesforce's search query
    query:
        data: get_user_search:message_data:message:body
        rkey_type: hash_map
        type: redis

    # type of the object
    searchBy:
        type: raw
        data:
            - type: contacts
              generalProperties:
                  - prefix: "First Name:"
                    propertyName: FirstName
                  - prefix: "Last Name:"
                    propertyName: LastName
              searchByProperties:
                  - Name
                  - Phone
                  - Email
            - type: accounts
              generalProperties:
                  - prefix: "Name:"
                    propertyName: Name
              searchByProperties:
                  - Name

# redis-key that will hold the response
# from search_objects
redis:
  field: get_service_search
  type: hash_map

# Check Missing Fields

Attribute: check_missing_fields

Check Missing Fields receives 4 parameters of email, phone, firstname and lastname, and returns the parameters that do not yet have values.
You will usually use this operation when we want to create a new contact, and we will want to make sure what parameters are missing to create the contact in salesforce.

# check_missing_fields is opeartion thats
# create note in salesforce.
type: Operation

# define the pointers to the
# internal app & app action
selector:
    app: salesforce
    app_action: check_missing_fields

# define the check_missing_fields payload
payload:
    # contact phone proprety
    phone:
        data: check_contact_info:phone
        rkey_type: hash_map
        type: redis

    # contact firstname proprety
    firstname:
        data: check_contact_info:firstname
        rkey_type: hash_map
        type: redis

    # contact lastname proprety
    lastname:
        data: check_contact_info:lastname
        rkey_type: hash_map
        type: redis

    # contact email proprety
    email:
        data: check_contact_info:email
        rkey_type: hash_map
        type: redis


# redis-key that will hold the response
# from check_missing_fields
redis:
  field: check_missing_response
  type: hash_map