import platformClient, { Models } from 'purecloud-platform-client-v2';
const client = platformClient.ApiClient.instance;
const conversationsApi = new platformClient.ConversationsApi();
const recordingApi = new platformClient.RecordingApi();
export const loginToGenesys = async () => {
client.setEnvironment('mypurecloud.jp');
const clientId = process.env.GENESYS_CLIENT_ID || Resource.ClientId.value;
const clientSecret =
process.env.GENESYS_CLIENT_SECRET || Resource.ClientSecret.value;
if (accessTokenExpiresAt < Date.now() + 60 * 1000) {
try {
const login = await client.loginClientCredentialsGrant(
clientId,
clientSecret,
);
accessTokenExpiresAt = login.tokenExpiryTime;
logger.info('Logged in to Genesys', {
expiresAt: accessTokenExpiresAt,
clientId,
});
} catch (error) {
logger.error('Failed to login to Genesys', { error });
throw error;
}
}
return client;
};