Answer Bot SDK in a nutshell

This page gives you the basic steps for getting up and running with the Answer Bot SDK.

The SDK is built on top of the Core SDK, which lays the foundation for multi-SDK interoperability.

What you need

  • Your organization has a Zendesk account with Guide and Answer Bot. You can register to start a free trial.

  • A Zendesk admin has registered your Android app in Zendesk. See Registering the application in Zendesk in the Help Center

  • The Zendesk admin has provided you with the initialization code for the app. The code was generated in Zendesk when the admin registered the app.

  • The Zendesk admin has enabled Answer Bot in the admin interface under Settings > Business Rules > Answer Bot.

Getting up and running

  1. Add the SDK to your project by including the following snippets in the build.gradle file:

    // Note: This is the root-level repositories container, not the one under 'buildScript'
    
    repositories {
        maven { url 'https://zendesk.jfrog.io/zendesk/repo' }
    }
    ...
    dependencies {
        implementation group: 'com.zendesk', name: 'answerbot', version: '1.0.1'
    }
    

    For details, see Adding the Answer Bot SDK.

  2. Initialize Zendesk in the onCreate() method of an Activity where you plan to use the SDK, or an Application subclass. Answer Bot requires both Zendesk and Support to be initialized in order to function. Use the initialization details provided by the Zendesk Support admin and a Context (in bold):

    @Override
    public void onCreate() {
        super.onCreate();
    
        Zendesk.INSTANCE.init(this, "zendeskUrl", "appId", "clientId");
    
        Identity identity = new AnonymousIdentity();
        Zendesk.INSTANCE.setIdentity(identity);
    
        Support.INSTANCE.init(Zendesk.INSTANCE);
        AnswerBot.INSTANCE.init(Zendesk.INSTANCE, Support.INSTANCE);
    }

    Note: If you're using multiple brands, you can use a brand subdomain rather than the primary subdomain in the zendeskUrl in the code above.

  3. Create an identity (in bold) so the app can authenticate as a Zendesk user, and set this on the Zendesk singleton:

    @Override
     public void onCreate() {
         super.onCreate();

     Zendesk.INSTANCE.init(this, "zendeskUrl", "appId", "clientId");
    
     Identity identity = new AnonymousIdentity();
     Zendesk.INSTANCE.setIdentity(identity);
     Support.INSTANCE.init(Zendesk.INSTANCE);
    
     AnswerBot.INSTANCE.init(Zendesk.INSTANCE, Support.INSTANCE);
    

    }

    There are two types of identity: anonymous and JWT. For details, see Setting an identity.

  4. Initialize the Answer Bot SDK using the Zendesk and Support singletons you just initialized:

    @Override
    public void onCreate() {
        super.onCreate();
    
        Zendesk.INSTANCE.init(this, "zendeskUrl", "appId", "clientId");
    
        Identity identity = new AnonymousIdentity();
        Zendesk.INSTANCE.setIdentity(identity);
        Support.INSTANCE.init(Zendesk.INSTANCE);
    
        AnswerBot.INSTANCE.init(Zendesk.INSTANCE, Support.INSTANCE);
    }

The Answer Bot SDK is now initialized and ready to be used.

Launching the Answer Bot SDK

The Answer Bot SDK provides the AnswerBotActivity class that has a static builder method you can use to start the activity. Example:

    AnswerBotActivity.builder()
        .show(context);

The builder can also return an Intent for the configured activity, to be started later. This is handy for PendingIntents and other asynchronous events. Example:

    Intent answerbotActivityIntent = AnswerBotActivity.builder()
       .intent(context);

You can even pass one activity's UiConfig to another activity, to be applied if one of them starts the other. For details, see Configuring the SDK activities.

For comprehensive reference documentation, see the Answer Bot SDK Javadocs on Github.

To see some samples of different ways to use the Zendesk mobile SDKs, have a look at our sample apps repo on Github.

Starting from the Support SDK

If you have Answer Bot 1.0.0 and Support SDK 3.0.0 (or above) in your app, then by default the contact button in HelpCenterActivity and ViewArticleActivity will open Answer Bot. You can disable this and direct the user straight to ticket creation using the following:

    HelpCenterActivity.builder()
            .withDeflectionEnabled(false)
            .config();

For more info see the HelpCenter docs.