Skip to content

Instantly share code, notes, and snippets.

View dugjason's full-sized avatar
:octocat:

Jason Dugdale dugjason

:octocat:
View GitHub Profile
@dugjason
dugjason / README.md
Last active November 2, 2023 19:42
Front API: Node.js script to merge contacts by email handle

merge-contacts.js

Uses the Front POST /contacts/merge API endpoint see docs to merge multiple contacts into a single contact record.

Installation

  1. Save the merge-contacts.js file to your local machine.
  2. Navigate to the directory you saved it.
  3. Run npm install axios to install the Axios HTTP client
  4. Edit the merge-contacts.js file to save your Front API token
@dugjason
dugjason / README.md
Created November 1, 2023 16:09
Front API: Send SMS message with vCard attachment

Inspired by Front's Node.JS attachment sample code at https://dev.frontapp.com/docs/attachments-1, this example will send an SMS message via your Front account containing a vCard (.vcf) attachment.

When appending the contact file to your formData object, ensure you set the filename as whatever you want the recipient to see as the name of the contact card.

@dugjason
dugjason / README.md
Created October 13, 2023 20:07
JavaScript script to split a CSV file into multiple smaller CSVs, sharing the same header

This script will take a .CSV file and split it into multiple files, each with a maximum specified number of rows. Each output file will have the same header row as the input file.

Usage:

node split-csv.js

You can modify the variables in the CONFIGURATION section below to change

@dugjason
dugjason / post_channels-channel-id-incoming-messages_inline-attachment.py
Created August 9, 2023 19:33
Python script to import message including inline image
# Type: Python3
# Description: Import a message including an inline image to a channel in Front.
# The image is encoded in base64 and included in the message body.
# API Endpoint Documentation: https://dev.frontapp.com/reference/post_channels-channel-id-incoming-messages
import base64
import requests
url = "https://api2.frontapp.com/channels/cha_123/incoming_messages"
@dugjason
dugjason / post_channels-channel-id-incoming-messages.py
Created August 9, 2023 15:50
Import a message with attachment to a channel in Front.
# Type: Python3
# Description: Import a message including an attachment to a channel in Front.
# API Endpoint Documentation: https://dev.frontapp.com/reference/post_channels-channel-id-incoming-messages
import requests
url = "https://api2.frontapp.com/channels/cha_123/incoming_messages"
# Note we need to specify nested attributes as `{parent[child]: value}` rather than `{parent: {child: value}}`
payload = {
@dugjason
dugjason / front-chat.tsx
Created April 27, 2023 19:49
Next.JS React component for Front Chat
// ./components/front-chat.tsx
"use client";
import Script from "next/script";
export function FrontChat() {
return (
<Script
id="front-chat-script"
@dugjason
dugjason / README.md
Created February 23, 2023 00:48
List message events from the Front API

Summary

This is a simple Node.JS script using the Front GET /events API endpoint fetching all "message" type events from the requester's Front account.

Requests are issued using Axios.

The script will respect your Front API rate limit.

Sign up at front.com

@dugjason
dugjason / channels-channel-id-incoming-messages.js
Last active March 15, 2022 18:23
This is a Node.JS demo of using Front's /channels/:channel_id/incoming_messages API endpoint. We are sending a request to receive an incoming message in Front, including an attachment
/**
* This is a Node.JS demo of using Front's /channels/:channel_id/incoming_messages API endpoint.
* We are sending a request to receive an incoming message in Front, including an attachment.
*
* See https://dev.frontapp.com/reference/post_channels-channel-id-incoming-messages for more details.
*/
const FRONT_API_TOKEN = 'YOUR FRONT API TOKEN';
const CHANNEL_ID = 'YOUR FRONT CHANNEL ID';
@dugjason
dugjason / listMessages.js
Created December 29, 2021 19:46
Front Plugin SDK: Using listMessages()
Front.contextUpdates.subscribe(context => {
console.log('Context:', context);
switch(context.type) {
case 'noConversation':
console.log('No conversation selected');
break;
case 'singleConversation':
console.log('Selected conversation context:', context);
@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>