@bitquirky/piece-goto-connect
Version:
GoTo Connect integration for ActivePieces
109 lines (108 loc) • 4.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendSms = void 0;
const pieces_framework_1 = require("@activepieces/pieces-framework");
const pieces_common_1 = require("@activepieces/pieces-common");
const auth_1 = require("../auth");
exports.sendSms = (0, pieces_framework_1.createAction)({
auth: auth_1.gotoConnectAuth,
name: 'send_sms',
displayName: 'Send SMS',
description: 'Send an SMS message using GoTo Connect',
props: {
from: pieces_framework_1.Property.Dropdown({
displayName: 'From',
description: 'Phone number to send SMS from',
required: true,
refreshers: [],
options: async (props) => {
// Debug what we receive
/* Debug logging
const debugInfo = {
auth_type: typeof props.auth,
auth_keys: props.auth ? Object.keys(props.auth) : 'auth is undefined',
props_keys: Object.keys(props)
};
console.debug('[GoToConnect] Dropdown props:', debugInfo);
*/
// First get the account info
try {
const token = props.auth.access_token;
const accountResponse = await pieces_common_1.httpClient.sendRequest({
method: pieces_common_1.HttpMethod.GET,
url: 'https://api.getgo.com/admin/rest/v1/me',
headers: {
'Authorization': `Bearer ${token}`,
'Accept': 'application/json'
}
});
// console.debug('[GoToConnect] Account Response:', accountResponse.body);
if (!accountResponse.body.accountKey) {
console.error('[GoToConnect] No accountKey in response'); // Removed response body from error log
return {
disabled: false,
options: [{
label: 'Error: Could not get account key',
value: 'error_no_account_key'
}]
};
}
// Then get the phone numbers
const response = await pieces_common_1.httpClient.sendRequest({
method: pieces_common_1.HttpMethod.GET,
url: `https://api.goto.com/voice-admin/v1/phone-numbers?pageSize=100&accountKey=${accountResponse.body.accountKey}`,
headers: {
'Authorization': `Bearer ${token}`,
'Accept': 'application/json'
}
});
// console.debug('[GoToConnect] API Response:', response.body);
return {
disabled: false,
options: response.body.items.map((number) => ({
label: number.number,
value: number.number
}))
};
}
catch (error) {
console.error('[GoToConnect] Error:', error instanceof Error ? error.message : 'Unknown error'); // Simplified error logging
return {
disabled: false,
options: [{
label: `Error: ${error instanceof Error ? error.message : 'Failed to fetch phone numbers'}`,
value: 'error'
}]
};
}
}
}),
to: pieces_framework_1.Property.ShortText({
displayName: 'To',
description: 'Phone number to send SMS to',
required: true,
}),
message: pieces_framework_1.Property.LongText({
displayName: 'Message',
description: 'Message content',
required: true,
}),
},
async run(context) {
const token = context.auth.access_token;
return await pieces_common_1.httpClient.sendRequest({
method: pieces_common_1.HttpMethod.POST,
url: 'https://api.jive.com/messaging/v1/messages',
headers: {
'Authorization': `Bearer ${token}`,
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: {
ownerPhoneNumber: context.propsValue.from,
contactPhoneNumbers: context.propsValue.to,
body: context.propsValue.message
}
});
}
});