Akia Developer Docs


Table of Contents
1. JavaScript Embed
2. Work Orders Webhook
3. Getting the organization ID



# JavaScript Embed SDK (1)


## Installation

Akia's chat interface can be embedded into any web-based interface. To 
install the SDK, put the following code in head or at the bottom of body. In order
for the SDK to work properly, Akia must whitelist the domain ahead of time.

  window.akiaInitialized = function() { 
    AKSDK.init({  
      partnerID: "", 
      sound: true, 
      onLoad: function(metadata) { 
        console.log('SDK initialized'); 
        document.getElementById('foo').innerHTML = metadata.unreadNotificationsCount;
      },    
      onNotify: function(notification, metadata) {      
        // Behavior when notify is called. Note that we already create a browser notification by default.      
        // metadata will contain unreadNotificationsCount, which contains the number of unread notifications.      
        // You can rely on this to render unread badges or "4 Unread Requests" in your UI      
        console.log('Notification received');      
        console.log(notification);      
        document.getElementById('foo').innerHTML = metadata.unreadNotificationsCount;    
      }   
    });  
    AKSDK.requestNotificationPermissions();
  };
  (function(d){  
    var s=d.createElement('script'), t=d.getElementsByTagName('script')[0];  
    s.src='/sdk.js';  
    t.parentNode.insertBefore(s,t);
  })(document);


## Open Dialog

We also provide the following function for your UI:

  AKSDK.openDialog();

This is a click handler for a button that may open the UI, usage:

  <button onclick="AKSDK.openDialog()">Open Akia</button>

This will then open a dialog that contains a slightly condensed version of our
UI (with no features missing).


## Close Dialog

This is also available to close the dialog. Used the same way as openDialog.

  AKSDK.closeDialog();
  
  
  
# Work Orders Webhook (2)

Akia customers can configure certain user intents to create webhooks.
The following are sample payloads that a server can expect from Akia when a
work order is created.

Akia will send these via POST request.


  // A generic request for housekeeping is provided.
  {
    organization_id: 123,
    type: "housekeeping",
    webhook_created_at: 1541894400,
    data: {
      workorder_id: 434,
      status: "new",
      message: "Can I get the room cleaned later this afternoon?",
      guest: {
        name: "Guest Name",
        id: 124,
        room_number: "921",
      },
    },
  }
  
  
  // An item is requested.
  {
    organization_id: 123,
    type: "requestitem",
    webhook_created_at: 1541894400,
    data: {
      workorder_id: 435,
      status: "new",
      message: "Can someone send up a toothbrush?",
      item: ["toothbrush"],
      guest: {
        name: "Guest Name",
        id: 124,
        room_number: "921",
      },
    },
  }
  
  
  // A work order is updated. We send these if the guest is sending
  // more information if after a work order is created.
  {
    organization_id: 123,
    type: "requestitem",
    webhook_created_at: 1541894400,
    data: {
      workorder_id: 435,
  	  status: "updated",
      message: "Can someone send up a toothbrush?; Oh and toothpaste?",
      item: ["toothbrush", "toothpaste"],
      guest: {
        name: "Guest Name",
        id: 124,
        room_number: "921",
      },
    },
  }
  
  
  // A work order is canceled.
  {
    organization_id: 123,
    type: "requestitem",
    webhook_created_at: 1541894400,
    data: {
      workorder_id: 435,
      status: "canceled",
    },
  }
  
  
  // A work order is completed.
  {
    organization_id: 123,
    type: "requestitem",
    webhook_created_at: 1541894400,
    data: {
      workorder_id: 435,
      status: "complete",
    },
  }
  
  

# Getting the Organization ID (3)

In order to get the organization ID programmatically, you can use the
javascript SDK, which will wrap an OAuth2 flow to grant permissions to make the
API call.

  <button onClick="login();">Connect Akia</button>
  
  function login() {
    AKSDK.login(function(data) {
      console.log(data.organizationID);
      // Save this value to the logged in user.
    });
  }