You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is what I have and what seems to be fine with the second code below. Kindly assist.
/**
* The script metadata object describes whether or not your extension should be invoked asynchronously, and which events it supports
* @returns {{ async: boolean, events: string[] }}
*/
function getScriptMetadata() {
return {
id: 'smsOnCheckIn',
displayName: 'SMS on Check-In',
version: 0,
async: true,
events: ['TICKET_CHECKED_IN']
};
}
function cleansePhoneNumber(phoneNumber) {
// Remove all non-digit characters
var cleaned = phoneNumber.replace(/\D/g, '');
// Check if it's a Nigerian mobile number
if (cleaned.length === 11 && cleaned.startsWith('0')) {
// Convert to international format
cleaned = '+234' + cleaned.substring(1);
}
return cleaned;
}
function postToWebhook(url, data) {
var response = simpleHttpClient.post(url, JSON.stringify(data)).asString();
return response.status;
}
function executeScript(scriptEvent) {
var ticket = scriptEvent.ticket;
log.log(Object.keys(scriptEvent).join(', ')); // To log only the keys in the event object
if (!ticket) {
log.warn('No ticket found in script event');
return;
}
// Code to fetch additional info such as phoneNumber may go here when available.
// Code to access phoneNumber from external storage may go here.
// Assuming phoneNumber is fetched from another source, commented the below line for now
// var phoneNumber = cleansePhoneNumber(ticket.additionalInfo.phoneNumber);
var phoneNumber = cleansePhoneNumber(ticket.phoneNumber);
log.log('Sending data to webhook for phone number ' + phoneNumber);
var message = "Hello, " + ticket.fullName + "! You have been successfully checked in.";
// Send data to the webhook
var webhookUrl = 'https://webhook.site/17735605-ba58-4f28-ba16-4e0c8c3a7b70';
var webhookData = {
ticketId: [ticket.id](http://ticket.id/),
phoneNumber: phoneNumber,
message: message
};
function postToWebhook(url, data) {
var response = simpleHttpClient.post(url, data) // changed line
.header('Content-Type', 'application/json')
.asString();
return response.status;
}
}
It started to fail when we looked at putting in the functions to post to the webhook, here is the code before then:
/**
* The script metadata object describes whether or not your extension should be invoked asynchronously, and which events it supports
* @returns {{ async: boolean, events: string[] }}
*/
function getScriptMetadata() {
return {
id: 'smsOnCheckIn',
displayName: 'SMS on Check-In',
version: 0,
async: true,
events: ['TICKET_CHECKED_IN']
};
}
function cleansePhoneNumber(phoneNumber) {
// Remove all non-digit characters
var cleaned = phoneNumber.replace(/\D/g, '');
// Check if it's a Nigerian mobile number
if (cleaned.length === 11 && cleaned.startsWith('0')) {
// Convert to international format
cleaned = '+234' + cleaned.substring(1);
}
return cleaned;
}
function executeScript(scriptEvent) {
var ticket = scriptEvent.ticket;
if (!ticket) {
log.warn('No ticket found in script event');
return;
}
// Code to fetch additional info such as phoneNumber may go here when available.
// Code to access phoneNumber from external storage may go here.
// Assuming phoneNumber is fetched from another source, commented the below line for now
// var phoneNumber = cleansePhoneNumber(ticket.additionalInfo.phoneNumber);
var phoneNumber = cleansePhoneNumber(ticket.phoneNumber);
log.log('Sending data to webhook for phone number ' + phoneNumber);
var message = "Hello, " + ticket.fullName + "! You have been successfully checked in.";
// Send data to the webhook
var webhookUrl = 'https://webhook.site/17735605-ba58-4f28-ba16-4e0c8c3a7b70';
var webhookData = {
ticketId: [ticket.id](http://ticket.id/),
phoneNumber: phoneNumber,
message: message
};
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This is what I have and what seems to be fine with the second code below. Kindly assist.
It started to fail when we looked at putting in the functions to post to the webhook, here is the code before then:
Beta Was this translation helpful? Give feedback.
All reactions