Created
July 25, 2023 09:09
-
-
Save jackcoldrick90/115dd34c9a5bcd3a7c948b41fb35be84 to your computer and use it in GitHub Desktop.
Snippets below can be used to create a custom coded bot in Hubspot that communicates with the TicketMaster Discovery API: https://developer.ticketmaster.com/products-and-docs/apis/getting-started/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.main = (event, callback) => { | |
var countryCode; | |
var country; | |
switch(event.userMessage.quickReply.quickReplies[0].value) { | |
case "Ireland": | |
countryCode = "IE" | |
country = "Ireland" | |
break; | |
case "United Kingdom": | |
countryCode = "GB" | |
country = "United Kingdom" | |
break; | |
case "United States": | |
countryCode = "US" | |
country = "United States" | |
break; | |
default: | |
countryCode = "IE" | |
country = "Ireland" | |
} | |
const responseJson = { | |
responseExpected: false, | |
customState: {countryCode: countryCode, country: country} | |
} | |
callback(responseJson); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request'); | |
const apikey = process.env['apiKey'] | |
exports.main = (event, callback) => { | |
var countryCode = event.session.customState.countryCode; | |
var country = event.session.customState.country; | |
var size = event.userMessage.message; | |
request("https://app.ticketmaster.com/discovery/v2/events?apikey=" + apikey + "&source=ticketmaster&countryCode=" + countryCode + "&size=" + size, function (error, response, body) { | |
var i; var msg = ""; | |
var events = JSON.parse(body)._embedded.events; | |
for(i = 0; i < size; i++){ | |
msg += `<img style="border-radius:5px;" src="${events[i].images[0].url}"></img><h4 style="font-size:14px;margin-bottom:0">${events[i].name}</h4><p>${events[i].dates.start.localDate}, ${events[i]._embedded.venues[0].name}</p><a href="${events[i].url}" target="_blank" style="display:inline-block;background: #024ddf;text-decoration: none;color: #fff;padding: 8px 24px;border-radius: 5px;font-weight: bold;margin-bottom:25px;margin-top:5px;">Book Now</a>`; | |
} | |
var responseJson = { | |
botMessage: `Here are ${size} events happening in ${country}:\n\n ${msg}`, | |
responseExpected: false | |
} | |
callback(responseJson); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment