Skip to content

Instantly share code, notes, and snippets.

@taf2 taf2/action.js Secret
Last active Nov 20, 2019

What would you like to do?
Super Page Example Page
const Mustache = require('mustache');
exports.handler = function(event, context, callback) {
let activity = event.activity;
// define our client side code here for easier debugging
let script = function() {
let form = document.getElementById('form');
console.log("execute the user script", form);
form.addEventListener('submit', function(e) { e.preventDefault();
// save the field data
console.log("save the form via CTM API");
let zip = document.getElementById('zip').value;
CTM.invoke('LDA8CA4483EED6CEF9E733131272ED71AB06B66737BACF304D7', {input: zip}).then(function(res) {
console.log("saved successfully", res);
let output =[1].data;
document.getElementById('output').innerHTML = '<p>' + output.replace(/say:Joanna:en-US:/,'') + '</p>';
}).catch(function(err) {
console.error("Something went wrong");
}, false);
script = '(' + script + ')()';
const response = {
statusCode: 200,
contentType: 'text/html',
script: script,
body: Mustache.to_html(`
<h3>Contact: ${} </h3>
<form id='form'>
<div class="field">
<label>Zip Code</label>
<input class='text' type='text' id='zip' name='zip' value='{{activity.postal_code}}'/>
<div id="output" class='card'></div>
<input type='submit' class='button' value='Lookup Weather'/>
`, {activity: activity}),
context.done(null, response);
console.log("the code ran");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.