Skip to content

Instantly share code, notes, and snippets.

@dugjason
Last active January 6, 2021 00:43
Show Gist options
  • Save dugjason/e7714dbbfa9e0f5f10fea38c627f56d2 to your computer and use it in GitHub Desktop.
Save dugjason/e7714dbbfa9e0f5f10fea38c627f56d2 to your computer and use it in GitHub Desktop.
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 => {
console.log('Context:', context);
let displayConversationIds = document.getElementById('selectedConversations');
let displayTeammate = document.getElementById('frontTeammate');
displayTeammate.innerHTML = 'Hello ' + context.teammate.name.split(' ')[0];
switch(context.type) {
case 'noConversation':
console.log('No conversation selected');
break;
case 'singleConversation':
console.log('Selected conversation context:', context);
let displayContact = document.getElementById('contact');
displayContact.innerHTML = context.conversation.recipient.handle;
displayConversationIds.innerHTML = context.conversation.id;
break;
case 'multiConversations':
console.log('Multiple conversations selected', context.conversations);
displayConversationIds.innerHTML = JSON.stringify(context.conversations.map(conversation => { return conversation.id }));
break;
default:
console.error(`Unsupported context type: ${context.type}`);
break;
}
});
</script>
</head>
<body>
<h3>Logged in Front Teammate</h3>
<p id="frontTeammate"></p>
<h3>Contact email</h3>
<p id="contact"></p>
<h3>ID(s) of selected conversation(s)</h3>
<p id="selectedConversations"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment