Rate this page:

Avatar

Methods

getResponseData

Copy URL
getResponseData(): 

AvatarMessageObject

|

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

sendMessageToAvatar

Copy URL
sendMessageToAvatar(config: 

AvatarConfig

):

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

Returns

  • type:

    Promise<unknown>

sendMessageToConversation

Copy URL
sendMessageToConversation(conversationUuid: 

string

,
message:

ChannelDataObject

):

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

Returns

  • type:

    Promise<unknown>

setAvatarApiUrl

Copy URL
setAvatarApiUrl(url: 

string

):

void

Parameters

  • url:

    string

Returns

  • type:

    void

stopAvatarSession

Copy URL
stopAvatarSession(config: 

AvatarStopSessionConfig

):

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

Returns

  • type:

    Promise<void>