Google Assistant Chatbase Analytics guide

in #google7 years ago (edited)

Google Assistant Chatbase analytics snippet

I couldn't find full examples of Chatbase integration for the Google Assistant other than the snippets in the chatbase-node readme, so here's the snippet recently created for Beyond Bitshares.

Recently, Dialogflow announced further Chatbot integration enabling session flow within the Dialogflow web UI, despite these recent improvements there is still additional functionality available within Chatbase worth exploring.

A quote from the above blog post:

We’re continually working with Chatbase, the cloud service for more easily analyzing and optimizing bots, on expanding the Analytics dashboard to help you monitor and improve agent performance.

Why use Chatbase?

Save time on bot analysis

Track key metrics like active users, sessions, and retention across multiple chat platforms.

Improve bot accuracy

Automatically identify problems and get suggestions for doing quick optimizations via machine learning.

Increase conversion rates

Visualize the flow of conversations to understand how efficiently users interact with your bot.

Source

Pre-Reqs

Include the following dependencies in your package.json:

    "@google/chatbase": "^1.1.0",
    "actions-on-google": "2.0.0-alpha.2",

Import the package: in your code:

Register on Chatbase, get your key and replace 'API_KEY' with it.

var chatbase = require('@google/chatbase')
              .setApiKey('API_KEY') // Your Chatbase API Key
              .setPlatform('Google Assistant'); // The type of message you are sending to chatbase: user (user) or agent (bot)

Create functions for errors and invalid input

function catch_error(conv, error_message, intent) {
  /*
  Generic function for reporting errors & providing error handling for the user.
  */
  chatbase_analytics(
    conv,
    `Error within intent ${intent}`, // input_message
    intent, // input_intent
    'error' // win_or_fail
  );

  if(error_message instanceof Error) {
      console.error(error_message);
  } else {
      console.error(new Error(error_message));
  }
  return conv.close(
      new SimpleResponse({
      // If we somehow fail, do so gracefully!
      speech: "An unexpected error was encountered! Let's end our Beyond Bitshares session for now.",
      text: "An unexpected error was encountered! Let's end our Beyond Bitshares session for now."
    })
  );
}

function invalid_input(conv, intent_name) {
  /*
  Reducing code duplication.
  Replace conv.close with a direction to a fallback intent in the future!
  */
  chatbase_analytics(
    conv,
    `User input invalid data within intent ${intent_name}`, // input_message
    intent_name, // input_intent
    'fail' // win_or_fail
  );

  return conv.close(
      new SimpleResponse({
      // If we somehow fail, do so gracefully!
      speech: "You provided invalid input data, try again with alternative input!",
      text: "You provided invalid input data, try again with alternative input!"
    })
  );
}

Then create the chatbase_analytics function:

Similarly in this section, change the 'API_KEY' to your chatbase analytics key.

function chatbase_analytics(conv, input_message, input_intent, win_or_fail) {
  /*
  Integrating chatbase chat bot analytics.
  Will help optimize user experience whilst minimizing privacy impact.
  */
  var userId = conv.user.id;

  if (win_or_fail === 'Win') {
    // For reporting successful bot interaction
    chatbase.newMessage('API_KEY')
    .setPlatform('Google Assistant')
    .setMessage(input_message)
    .setVersion('1.0')
    .setUserId(userId.toString())
    .setAsTypeUser() // sets the message as type user
    .setAsHandled() // set the message as handled -- this means the bot understood the message sent by the user
    .setIntent(input_intent) // the intent of the sent message (does not have to be set for agent messages)
    .setTimestamp(Date.now().toString()) // Only unix epochs with Millisecond precision
    .send()
    .then(msg => console.log(msg.getCreateResponse()))
    .catch(err => console.error(err));
  } else {
    // For reporting fallback attempts
    chatbase.newMessage('API_KEY')
    .setPlatform('Google Assistant')
    .setMessage(input_message)
    .setVersion('1.0')
    .setUserId(userId.toString())
    .setAsTypeUser() // sets the message as type agent
    .setAsNotHandled() // set the message as not handled -- this means the opposite of the preceding
    .setIntent(input_intent) // the intent of the sent message (does not have to be set for agent messages)
    .setTimestamp(Date.now().toString()) // Only unix epochs with Millisecond precision
    .send()
    .then(msg => console.log(msg.getCreateResponse()))
    .catch(err => console.error(err));
  }
}

Then finally - call the function at the end of intents

For successful intent outcome

chatbase_analytics(
  conv,
  'About page', // input_message
  'About', // input_intent
  'Win' // win_or_fail
);

For invalid user input outcome

return invalid_input(conv, `account_balances`);

For handling errors

return catch_error(conv, error_message, 'account_balances');

Input message contents?

Try to include useful information, like what the user did in the function, including potentially limited input variable information.


Have any questions about the above? Just write a comment below!

Cheers,
@cm-steem

Sort:  

Google always gives us wonderful and interesting facilities and product...
Chatbase is one of them, It has really amazing facilities...specially Improve bot accuracy...its just fabulous.. I have a question..i use it in laptop. Is chatbase mobile apps has been launched?? @cm-steem

Is chatbase mobile apps has been launched??

Not sure, I'm only using the web interface for their analytics, it does appear that they offer A/B testing functionality to mobile devices, that'd be great in the google assistant! I don't see any official chatbase android app though.

Thanks @cm-steem.. If there have no chatbase official mobile apps, hope that mobile apps will be launched soon...

Wow way too advanced for me ! Gotta research this more.

To listen to the audio version of this article click on the play image.

Brought to you by @tts. If you find it useful please consider upvote this reply.

@cm-steem its really amazing. thanks for this important information share with us. I have question for you. if i lost my code then what can i do?

If you lost your chatbase api key code? You can easily retrieve it from their web ui.

oh i see. that's good. @cm-steem thanks for your feedback. tomorrow i will be registerd on here. i hope it will be well.

You got a 66.67% upvote and resteem from @ebargains courtesy of @cm-steem. Thank you for using the @ebargains UPVOTE and RESTEEM bot.

If you are looking to earn a passive no hassle return on your Steem Power, delegate your SP to @ebargains by clicking on one of the ready to delegate links:
50SP | 100SP | 250SP | 500SP | 1000SP | 5000SP | Custom Amount

You will earn 80% of the voting bot's earnings based on your delegated SP's prorated share of the bot's SP pool at the end of EACH voting round! That is up to 38.5% APR! You can also undelegate at anytime.

Google Assistant Chatbase useage very important for us. sometimes we want to more information & our ptoblemetic soluation. that time we knock to Googlr assistant chatbase & find out our answer.

I trying to use by mobile phone, so many time i trying it but i can't to this.
I think this chatbase not available for mobile phone.

@cm-steem Thank you so much for your kind information

i don't knew about Google have any Chatbase, if it have then it is very well for us. how can I Register on Chatbase??
I am very intersted & excited so @cm-steem you if you have any link fot registration so give me please. I needed.

https://chatbase.com/welcome

Uses a google authentication system, so make a google account :)

okay. thanks for your kind information.

Very nice post and good information

nice information&post
@upvote & @resteem done

nice post @cm-steem

Coin Marketplace

STEEM 0.36
TRX 0.26
JST 0.039
BTC 95204.76
ETH 3397.86
USDT 1.00
SBD 3.61