Avatar
Methods
getResponseData
getResponseData(): | null
Gets response data from an avatar.
const kit = new VoximplantKit(context);
if (kit.isAvatar()) {
const avatarResponse = kit.avatar.getResponseData();
console.log(avatarResponse);
// ... do something
}// End of function
callback(200, kit.getResponseBody());
Returns
type:
type:
null
sendMessageToAvatar
sendMessageToAvatar(config: ): Promise<unknown>
Send a message to a Voximplant avatar.
const kit = new VoximplantKit(context);
if (kit.isMessage()) {
try {
const conversationId = kit.getConversationUuid();
const callbackUri = kit.getFunctionUriById(33);
const {text} = kit.getIncomingMessage();
// This variable must be added to the environment variables yourself.
const avatarId = kit.getEnvVariable('avatarId');
const voxAccountId = kit.getEnvVariable('VOXIMPLANT_ACCOUNT_ID');
const avatarLogin = kit.getEnvVariable('VOXIMPLANT_AVATAR_LOGIN');
const avatarPass = kit.getEnvVariable('VOXIMPLANT_AVATAR_PASSWORD');
await kit.avatar.sendMessageToAvatar({
callbackUri,
voxAccountId,
avatarLogin,
avatarPass,
avatarId,
conversationId,
utterance: text,
customData: {}
})
} catch (err) {
console.error(err);
}
}// End of function
callback(200, kit.getResponseBody());
Parameters
config:
Returns
type:
Promise<unknown>
sendMessageToConversation
sendMessageToConversation(conversationUuid: string
, message: ): Promise<unknown>
Send the avatar's reply to the conversation.
const kit = new VoximplantKit(context);
if (kit.isAvatar()) {
const conversationUuid = kit.getConversationUuid();
const message = kit.getMessageObject();
try {
await kit.avatar.sendMessageToConversation(conversationUuid, message);
} catch(err) {
console.error(err)
}
}// End of function
callback(200, kit.getResponseBody());
Parameters
conversationUuid:
string
message:
Returns
type:
Promise<unknown>
setAvatarApiUrl
setAvatarApiUrl(url: string
): void
Parameters
url:
string
Returns
type:
void
stopAvatarSession
stopAvatarSession(config: ): Promise<void>
Terminates an avatar session.
const kit = new VoximplantKit(context);
// This variable must be added to the environment variables yourself.
const avatarId = kit.getEnvVariable('avatarId');
const conversationId = kit.getConversationUuid();
const voxAccountId = kit.getEnvVariable('VOXIMPLANT_ACCOUNT_ID');
const avatarLogin = kit.getEnvVariable('VOXIMPLANT_AVATAR_LOGIN');
const avatarPass = kit.getEnvVariable('VOXIMPLANT_AVATAR_PASSWORD');
if (kit.isAvatar()) {
try {
await kit.avatar.stopAvatarSession({
voxAccountId,
avatarLogin,
avatarPass,
avatarId,
conversationId,
})
} catch (err) {
console.error(err);
}
}
// End of function
callback(200, kit.getResponseBody());
Parameters
config:
Returns
type:
Promise<void>