Skip to content

Instantly share code, notes, and snippets.

View HubSpotHanevold's full-sized avatar

Tyler Hanevold (HubSpot) HubSpotHanevold

View GitHub Profile
exports.main = async (event, callback) => {
var phone = event.inputFields['phone'];
console.log("Input Phone: ", phone)
const outputFields = {
valid: false,
validation_message: "",
phone: ""
}
<script>
document.addEventListener("DOMContentLoaded", function() {
// Wait for the form to load
setTimeout(function() {
var urlInput = document.querySelector('input[name="url_of_page"]');
if (urlInput) {
console.log('url_of_page input exists');
urlInput.value = window.location.href;
}
},1000); // Adjust the delay if needed
@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 %}