Table of Contents
Extract full name from capture conversation
{%- set full_name = __conversation
| selectattr("label", "in", "Greeting and Full name Nombre")
| map(attribute="answer_text") | list | last
%}
{
"first_name": "{{ full_name.split(' ', 1)[0] if full_name else first_name }}",
"last_name": "{{ full_name.split(' ', 1)[1] if full_name else last_name }}"
}-
Set – Sets an new attribute equal to the full conversation they had
selectAttr - Pullsthe specific question asked in the conversation. - Map – Creates a new array from the answer text.
- List – Converts the array to a list.
- Last – Grabs the last element out of the list.
- string.split(' ') – Turns the string into an array of items based on the delineator (space in this case).
Format conversation into string transcript
{
"notes": "AI Conversation Transcript\n {% for item in __conversation
%}Olivia: {{item.message_question_text | regex_replace('\n|"', ' ')}}\n{%
if item.answer_text
%}{{first_name}}: {{item.answer_text | regex_replace('\n|"', ' ')}}\n{%
endif
%}{%
endfor
%}"
}- For - Loop through each element of the conversation. Each element is then broken into its individual parts of question and answer then listed with the appropriate name.
Date Diff for Age
{% set birth_date = "2002-02-01" %}
{% set ONE_YEAR = 31536000 %}
{% set dob_timestamp = birth_date | strptime_to_timestamp("%Y-%m-%d") %}
{% set years_old = (__current_timestamp - dob_timestamp) // ONE_YEAR %}
years_old: {{years_old}}- strptime_to_timestamp – Converts given time format to Epoch time. Years old is then calculated by (current date - dob)/ year.
Generate a Random GUID
Input
{%- macro random_string(len) -%}
{%- for i in range(0,len) -%}{{ [0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"]|random }}
{%- endfor -%}
{%- endmacro -%}
{%- macro random_guid() -%}{{ random_string(8) + "-" + random_string(4) + "-" + random_string(4) + "-" + random_string(4) + "-" + random_string(12) }}{%- endmacro -%}
{%- set myGUID = random_guid() -%}
"test": "{{myGUID}}"Output
"test": "9ea92b4a-f1d6-7f22-bb39-cbd8f2e2ed0b"- random – Returns a “random” element from the array piped into random.
Get a recruiter’s employee ID
{{ __hiring_team_users | rejectattr('acl_role', 'in', ['Hiring Manager - Global', 'Hiring Manager']) | map(attribute='employee_id') | first }}- rejectattr – Filter out users from the array who have the role Hiring Manager.
- Map Attribute – Makes an array of the just the attribute specified.
- First – get the first in the array.
Convert array to comma separated list
"interviewer_emails":"{% for user in interviewList %}{{user}}{% if not loop.last %}, {% endif %}{% endfor %}""- For – Looping through each user in the list.
- if not loop.last – Used to separate elements by a comma, not adding one to the last element to keep proper formatting.
Extract country code
{% set phone_country_code, phone_country_code_str, phone_national_number = phone_number|extract_phone_number %}Date formatting
If you need to reformat a date from one format to another. For example, change 2023-09-30 to a format of 09/30/2023.
{{start_date | strptime('%Y-%m-%d') | strftime('%m/%d/%Y')}}- strptime is taking a string and converting to a timestamp based on the argument passed of the date format from the string. strptime (STRing Parse to TIMEstamp)
- strftime is taking a unix timestamp and converting to date format based on the argument passed. strftime (STRing Formatter from TIMEstamp object)
Epoch date formatting
if you need to reformat a epoch date with date and epoch example: /Date(1058313600)/, and format it like 2003-07-16,
{{attribute | regex_replace('[\D]', '') | int | strftime("%Y-%m-%d")}}This will convert it to that format.
Macro - Extract a question from a list that has a specific ID
If you have a JSON array and you want to get some attribute where another attribute matches some value.
{%- set test = [{'id':'107-119','question':'Are you able to lift 50 lbs?'},{'id':'107-135','question':'Which shift(s) are you able to work?'}] -%}
{%- macro get_question_by_id(data, target_id) -%}
{%- for item in data -%}
{%- if item['id'] == target_id -%}
{{ item['question'] }}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{%- set target_id = '107-119' -%}
{{ get_question_by_id(test, target_id) }}This will output:
Are you able to lift 50 lbs?An example of the inverse of this (get an ID based on a question match), and where the value is in a stored attribute (i.e. currently as a string). So the same value as “test” above, but stored in a string.
So here the initial regex_replace is taking steps to convert the string into JSON.
{%- set question_json = job_posting_questions|regex_replace('\'','"')|regex_replace('True','true')|regex_replace('False','false')|parse_json -%}
{%- macro get_question_by_id(data, target_id) -%}
{%- for item in data -%}
{%- if target_id in item['question']|string -%}
{{ item['id'] }}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
"id": "{{ get_question_by_id(question_json, 'lift 50 lbs') }}"Outputs:
"id": "107-119"Date stamp for ‘Tomorrow’
{{((__current_date | strptime_to_timestamp("%Y-%m-%d")) + 86400) | strftime("%Y-%m-%d")}}Remove control characters
If you have an ASCII control character in your payload causing it to be invalid. The following regex will remove all control characters. The photo below has the control character BEL.
{{ text | regex_replace('[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\x9F]', '') }}