Skip to content

Instantly share code, notes, and snippets.

View HubSpotHanevold's full-sized avatar

Tyler Hanevold (HubSpot) HubSpotHanevold

View GitHub Profile
@HubSpotHanevold
HubSpotHanevold / gist:2c341624ba9ba17d446146581c12a21c
Last active July 22, 2024 19:12
Convert html in rich text to friendly text
exports.main = async (event, callback) => {
let originalString = 'TEXTGOESHERE';
let updatedString = originalString.replace(/<br>/g, ';')
let nextupdatedString = updatedString.replace(/<(?=\s*[^a-zA-Z\/])/g, '****');
let nextnextupdatedString = nextupdatedString.replace(/<[^>]*>|#nextsteps|&nbsp;/g, '')
let finalString = nextnextupdatedString.replace(/\*\*\*\*/g, '<');
@HubSpotHanevold
HubSpotHanevold / sample.html
Created June 12, 2024 19:53
Putting calendar meeting times into an email
{# NOTE THESE CAN ALL BE ADJUSTED TO USE PLACEHOLDER VALUES INSTEAD OF DEFINED IN THE CODE #}
{# START AND END TIMES FOR THE EVENT #}
{% set google_start_time = "T230000Z" %}
{% set google_end_time = "T240000Z" %}
{% set outlook_start_time = "T23:00:00+00:00"|urlencode %}
{% set outlook_end_time = "T24:00:00+00:00"|urlencode %}
{# STATIC VALUES - DEFINED #}
{% set event_title = "Sample webinar title"|urlencode %}
const axios = require('axios');
const crypto = require('crypto');
exports.main = async ({ body }, sendResponse) => {
if(body.event == 'endpoint.url_validation'){
try {
sendResponse({ body: {encryptedToken: crypto.createHmac('sha256', 'TOKEN ADDED HERE').update(body.payload.plainToken).digest('hex'), plainToken: body.payload.plainToken}, statusCode: 200 });
} catch(e){
sendResponse({ body: e, statusCode: 200 });
}
@HubSpotHanevold
HubSpotHanevold / gist:4389bf7555a0cb33074588e84ba4b17c
Last active May 16, 2024 20:03
Abandoned Cart Email Module Example
<!-- REMEMBER 'USE MODULE FOR PROGRAMMABLE EMAIL' MUST BE SELECTED -->
<!-- RETRIEVE PAYLOAD DATA FROM CONTACT RECORD -->
{% set cart_items = contact.abandoned_cart_json_payload | fromjson %}
<!-- HEADER ROW -->
<table style="width: 100%; border-collapse: collapse;">
<tr>
<th style="width: 20%; text-align: left; font-weight: bold; border: none;"></th>
<th style="width: 60%; text-align: left; font-weight: bold; border: none;"></th>
<th style="width: 10%; text-align: right; font-weight: bold; border: none;">Qty</th>
const axios = require('axios');
exports.main = async (event, callback) => {
try {
// Replace with secret name
const auth = process.env.SAMPLESECRETNAME;
// Replace variables below as needed
const hsObjectId = event.inputFields['hs_object_id'];
const cpa = event.inputFields['cpa____'];
{# NOTE THESE CAN ALL BE ADJUSTED TO USE PLACEHOLDER VALUES INSTEAD OF DEFINED IN THE CODE #}
{# START AND END TIMES FOR THE EVENT #}
{% set google_start_time = "T230000Z" %}
{% set google_end_time = "T240000Z" %}
{% set outlook_start_time = "T23:00:00+00:00"|urlencode %}
{% set outlook_end_time = "T24:00:00+00:00"|urlencode %}
{# STATIC VALUES - DEFINED #}
{% set event_title = "Sample webinar title"|urlencode %}
exports.main = async (event, callback) => {
const old_plan_amount = event.inputFields['old_plan_amount'];
const new_plan_amount = event.inputFields['new_plan_amount'];
if(old_plan_amount == new_plan_amount) {
callback({
outputFields: {
delta: 'none'
}
@HubSpotHanevold
HubSpotHanevold / omit blog ids with hubl.js
Created January 30, 2023 16:36
A way to omit certain blogs from filtered lists via HubL array
{% set used_ids = [1, 2, 3, 5, 6] %}
{% set new_ids = [1, 2, 4, 5, 7, 8] %}
{% set ids_to_use = new_ids|difference(used_ids) %}
{% for id in ids_to_use %}
{{id}}
{% endfor %}
@HubSpotHanevold
HubSpotHanevold / auto increment a deal record using crm search api.js
Last active January 17, 2023 18:28
This custom coded action takes the most recent value from the record type in question then adds a value to that previous amount. Use this code for auto incrementing records.
var axios = require('axios');
const auth = 'Bearer ' + process.env.ADD_YOUR_SECRET_KEY_NAME_HERE;
exports.main = async (event, callback) => {
var data = JSON.stringify({
"filterGroups":[
{
"filters":[
{
@HubSpotHanevold
HubSpotHanevold / appending dropdown multi-picklist when value does not exist.php
Last active January 12, 2023 16:51
A php webhook endpoint that will append a multi-picklist with missing values. Also, returns the property update values in an easy way to use in a custom code action later in the workflow.
<?php
// RETRIEVE THE CURRENT DROPDOWN VALUES FOR THE LINE-ITEM PROPERTY
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.hubapi.com/crm/v3/properties/deal/line_items',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,