Skip to content

Instantly share code, notes, and snippets.

View dugjason's full-sized avatar

Jason Dugdale dugjason

View GitHub Profile
@dugjason
dugjason / index.html
Created April 8, 2021 22:59
Simple HTML + JS example of Front Context API plugin
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
<script type="text/javascript" src="//dl.frontapp.com/libs/plugin-sdk-1.0.1.min.js"></script>
<title>Front Plugin v1</title>
</head>
@dugjason
dugjason / send-message-with-attachment.php
Created April 8, 2021 17:08
Front API: Basic PHP example of sending a message with an attachment using Front's API
<?php
require './../vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://api2.frontapp.com/',
'headers' => [
'Authorization' => 'Bearer [FRONT_API_TOKEN]',
'Content-Type' => 'multipart/form-data',
@dugjason
dugjason / README.
Created April 6, 2021 21:59
Front API: Applying tags to custom conversations
## Overview
This example shows us how to create a conversation in Front using the Receive custom messages
endpoint (https://dev.frontapp.com/reference/messages-1#post_channels-channel-id-incoming-messages),
then apply a tag to that newly created conversation based on the message_uid attribute returned
from that API call.
## Implementation
1. Create the inbound message, using the "Receive Custom Messages" endpoint - https://dev.frontapp.com/reference/messages-1#post_channels-channel-id-incoming-messages
2. Grab the `message_uid` from that response
3. Use Resource aliases ( https://dev.frontapp.com/reference/introduction#resource-aliases ) with the `GET /messages` endpoint to fetch the message by UID
@dugjason
dugjason / index.html
Created March 26, 2021 16:23
Front Context API - Updating Drafts
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>Front Plugin</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="//dl.frontapp.com/libs/plugin-sdk-1.0.1.min.js"></script>
</head>
<body>
@dugjason
dugjason / use-nvm-node.sh
Created March 3, 2021 18:20
On changing directory, ensure you use the Node version specified by the directory .nvmrc file if present
# place this after nvm initialization!
# Inspired by https://github.com/nvm-sh/nvm#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file
autoload -U add-zsh-hook
load-nvmrc() {
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -e "$nvmrc_path" ]; then
local node_version="$(nvm version)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
@dugjason
dugjason / send-message-with-attachment.js
Created January 15, 2021 21:30
Send an email message with an attachment via Front's API
const FRONT_API_TOKEN = 'YOUR FRONT API TOKEN GOES HERE';
const CHANNEL_ID = 'YOUR FRONT CHANNEL ID GOES HERE';
const FormData = require('form-data');
const fs = require('fs');
// abstract and promisify actual network request
async function makeRequest(formData, options) {
return new Promise((resolve, reject) => {
const req = formData.submit(options, (err, res) => {
@dugjason
dugjason / index.html
Last active January 6, 2021 00:43
Basic single-page Front Context API Plugin
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>Basic Front Plugin</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="//dl.frontapp.com/libs/plugin-sdk-1.0.1.min.js"></script>
<script type="text/javascript">
Front.contextUpdates.subscribe(context => {
@dugjason
dugjason / front_chat_user_verification.rb
Created August 28, 2019 16:35
User Verification for Front Chat in Ruby
userHash = OpenSSL::HMAC.hexdigest("SHA256", ENV['FRONTAPP_VERIFICATION_KEY'], email)
@dugjason
dugjason / front_chat_user_verification.php
Created May 29, 2019 20:13
User Verification for Front Chat in PHP
$userHash = hash_hmac('sha256', $userEmail, $verificationSecret);
@dugjason
dugjason / frontapp_webhook.rb
Created April 19, 2018 23:29
Simple Sinatra server that will accept webhook payloads from Front, and verify their authenticity
require 'sinatra'
require 'openssl'
require 'Base64'
SECRET_KEY = "your-secret-key"
post '/payload' do
payload = request.body.read