Building chatbot with amazon lex and lambda

“Amazon Lex is an AWS service for building conversational interfaces for any applications using voice and text.”

Amazon lex uses the same deep learning technology as Alexa. With Lex you can create your speech or text chatbots which can provide seamless natural language experience.

This bots can be integrated with other services provided by AWS like Lambda, MobileHub and CloudWatch etc. Lex allows you to easily publish the chatbots to mobile devices and to 3rd party messaging service like Slack, facebook messenger.

At the moment AWS Lex is only available in two regions US EAST (N. Virginia) and EU (Ireland). You can start with one of the sample chatbots (BookTrip, OrderFlowers, SceduleAppointments) provided by amazon or build your custom one from scratch.

Intents, Utterances, Slots, Prompts and Fulfillment are the basic components of amazon Lex. The picture below explains the basic components for hotel booking, one of the sample bots provided by amazon lex.

Here, my goal is to create a custom chatbot with the intent to register users for pre-defined event types.
You can create sample utterances, provide type of input that user should prompt to user to fulfil the intent. Here I am going to create a custom slot type from aws CLI.
"enumerationValues": [
"value": "AwesomeDay"
"value": "BuildersDay
"name": "EventTypesValue",
"description": "Types of Event to register”

Save above code as EventTypes.json

Now lets create this custom SlotType from the json using AWS CLI

Configure your AWS CLI with accesskey for your account. Use put-slot-type for creating custom slot type. Once deployed you can add it to the slots for your bot.

aws lex-models put-slot-type \
--region eu-west-1 \
--name EventTypesValue \
--cli-input-json file://EventTypes.json

Lets create the lambda function in the same region to support bot’s fulfilment. I have created custom lambda function in python as below:

import uuid
def lambda_handler(event, context):
id = registerUser(event)
message = 'Okay, I have registerd you. Your registration no is {}'.format(id)
state = 'Fulfilled'
response = {
'dialogAction': {
'type': 'Close',
'fulfillmentState': state,
'message': message
return response

Assign lambda function that we just created to fulfilment intent.

Build and test your chatbot.


Digital Transformation – the change, cloud and Microservices

When most businesses have claimed to turned into complete digital or going through digital transformation, It is important that we understand what it means actually. The change need to be in every aspect of business from HR to Sales, from marketing to IT, from finance to external communication. True Digital transformation strategy should aim to empower not only customers but also end-users, stakeholders, employees and everyone involved in supporting business process and organisation.

Digital transformation is continuous and ongoing process. Growth, getting more users and more usability of the service with maintaining quality is the heart of every business. Your business plan , product roadmap should lead towards (high -growth if you are a startup)  scalable services (scalable resources ), available from anywhere (cloud resources).

Change is constant

Executives need to build strategy around constant change. continuous improvement in the services and operation to reflect recent requirements. Companies need to build culture of embracing constant change by changing gradually by small improvements that lead to bigger outcome at the end. All small change that lead to be empowering your team, investing in your employees and customers, acquiring startups for innovations or investing in innovation and research. Taking little calculative risks to try new things is very essential for innovation and improvement in services and products.

Moving to Cloud

Most of the IT cost of business is in maintenance of software services and resources and towards man hours invested in this task. By storing software resources in the cloud you will only pay for the services or resources you use per hours. Cloud resources are scalable and reliable, hence you can scale up or down as per your business needs. Almost all businesses consider the upfront price of the software and fail to project real maintenance and support cost of the software services which lead to keep total ownership of everything in-house and it is really costly compare to cloud resources.

Iaas (Infrastructure as a service) – This provides basic compute processing, storage , networking services which can be accessed from anywhere. Owners get maximum control on resources and can choose their operating system, security rules. With control, owners also need to manage the resources like installing updates and patches. Example: Azure VMs, AWS compute instance etc.

Paas (Platform as a service) – This provides the platform to develop software and services using programming languages, apis and tools supported by providers. Owners have less control on infrastructure but they do not  manage them. Example : Azure app, website on AWS etc.

Saas (Software as a service) – Businesses buy the software as services and do not need to worry about managing infrastructure or developing software. They are already built application running in the cloud. Owners don’t have much option to customise it. Example: outlook, office 365, etc.


To support digital transformation road-map our software infrastructure, services and product should lead to the next evolution in software architecture, which allow services to be faster, scalable and more manageable.

Traditional monolithic applications are built with tightly coupled components which are deployed as single entity. This makes development, testing and deployment difficult and therefore providing releases, new features and updates are very tedious and long process. Micro-services architecture breakdown this tightly coupled components and model them into individually deployable.

Because of being independent these components can be developed, tested and deployed separately and also can be scaled separately as well. You see your whole service or application does not need to be highly scaled most of the time only particular components and this can be achieved through Microservices. Isn’t that beautiful!!

Keeping components separate gives freedom to choose different technologies, languages and platforms. This makes it possible them to be build and managed by separate teams.

Containers provide better way to manage your IT infrastructure and better way to deploy and maintain your application, which will significantly speed up the digital transformation process. Containers provide isolated environment to run your services. It holds all necessary components like dlls, config files, environment files and variables to run that (micro) service or software. You can put constrains on how much physical resources – memory and CPU can be used by a container, so a single container can not consume beyond that limit. Beautiful again !! Control on machines is beautiful !!

In the era where DevOps is rising, It is important that we don’t forget continuous deployment and test driven development. DevOps is an approach that fills the gap between software development and delivery process. It encourages automating and monitoring build, deployment, testing , integration and releasing product/service or change. Let’s machines and bots take the repetitive task and let humans focus on solving real problems.

As a final note, Digital Transformation is just a new term of empowering and supporting our employees, customers, services, everyone and everything that supports Growth and helps to fulfil the organisation’s purpose. Growth without purpose is like a road to no where so make sure you don’t loose the purpose on your journey!! Embrace the change. Nothing is more beautiful than a change!!

Article 30 from 30 : Licensing your app

This post is article 30 from the 30 Articles App series for SharePoint

In this article, I will discuss about Licensing your SharePoint app on office store.

When you upload your app on the Office Store for publication, you can choose the terms of the license you want to offer, like offering your app for free, trial, or for purchase. Or your app can be acquired on a per-user or site basis.

SharePoint provides a licensing framework that lets you include code logic in your app to enforce whatever licensing restrictions you choose. For example, you can include code logic in your app that enables users to access certain app features if they have a paid license, but not if they have a trial license.

A user with a license for an app can use that app on any site for that particular SharePoint deployment. In general, for the purpose of app licenses, deployment is defined as the SharePoint farm for on-premises SharePoint installations, and the tenancy for SharePoint Online in Office 365. The app’s purchaser can manage the app license, assign those app licenses to other users within their deployment, and enable other users to manage the licenses. A user who is assigned an app license can access and use the app.

For apps for SharePoint that have a per-user license, each app license can be assigned to the specified number of SharePoint users. The app license applies only to the specified SharePoint deployment and the specified users.
For apps with a site license, that license is assigned to all users on that deployment automatically. You cannot programmatically assign app licenses.

App license query and validation process :
1. The user launches the app from within SharePoint.
2. This launches the app code in the cloud.
3. When the app needs to verify a user’s app license, it uses server-side code to query SharePoint, via the client object model, for the app license token.
4. It then passes that token to the Office Store verification service.
5. The verification service returns whether the license token is valid, and if it is, also returns the license properties.
6. The app can then take action, based on the validity of the license and its properties



Finally, after you finish testing your app and are ready to move it to production, you need to add code to the license checks in your app so that the app no longer accepts test licenses.

Let’s validate app’s Validate the app license token in code:

Retrieving app license tokens using GetAppLicenseInformation :

productId = new Guid();
using(ClientContext ctx = new ClientContext(webUrl))
    ClientResult licensecollection = Microsoft.SharePoint.Client.Utilities.Utility.GetAppLicenseInformation(ctx, productId);

Validating the app license token
After you retrieve the appropriate app license token, pass that token to the Office Store verification web service for validation. The verification service is located at the following URL:

The Office Store license verification web service also supports verifying app license tokens using REST calls. To verify an app license by using REST, use the following syntax:

Where {token} is the app license token

For test app licenses, the IsTest property returns true and the IsValid property returns false.
This sample requires a reference to Microsoft.SharePoint.Client.Utilities, and a web service reference to the Office Store verification service.

retrieving app license tokens : GetAppLicenseInformation

//Get the license token XML from SharePoint.
this.rawToken = GetLicenseTokenFromSP(this.productId, this.clientcontext);

//Call the Office Store verification service.

private string GetLicenseTokenFromSP(Guid productId, ClientContext clientContext)
    //Get the license from SharePoint.
    ClientResult licenseCollection = Utility.GetAppLicenseInformation(clientContext, productId);

    foreach (AppLicense license in licenseCollection.Value)
        //Just get the first license token for now.
        rawLicenseToken = license.RawXMLLicenseToken;
    return (rawLicenseToken);

private void VerifyLicenseToken(string rawLicenseToken)
    if (string.IsNullOrEmpty(rawLicenseToken))
        licVerifyEndPoint.Text = "There is no valid license for this user in SharePoint (OR) license cannot be obtained due to some error - check ULS.";

    VerificationServiceClient service = null;
    VerifyEntitlementTokenResponse result = null;
    VerifyEntitlementTokenRequest request = new VerifyEntitlementTokenRequest();
    request.RawToken = rawLicenseToken;
    lblSPLicenseText.Text = System.Web.HttpUtility.HtmlEncode(request.RawToken);   

        service = new VerificationServiceClient();
        result = service.VerifyEntitlementToken(request);
    catch (EndpointNotFoundException)
        licVerifyEndPoint.Text = "Cannot access verification service endpoint";
    catch (FaultException)
        licVerifyEndPoint.Text = "Error: entitlement verification service is unavailable.";
    catch (FaultException internalFault)
        licVerifyEndPoint.Text = "Error: entitlement verification service failed. Details: " + internalFault.Detail.Message;
    catch (Exception exception)
        licVerifyEndPoint.Text = "Error: entitlement verification service failed. Details: " + exception;

    if (result != null && result.AssetId !=null)
        string licenseDetails = string.Format("Asset Id: {0}; Product Id: {1}; License Type: {2}; Is Valid: {3}; License Acquisition Date: {4}; License Expiry Date: {5}; IsExpired: {6}; IsTest: {7}; IsSiteLicense: {8}; Seats: {9}; TokenExpiryDate: {10}",
                result.AssetId, result.ProductId, result.EntitlementType, result.IsValid, result.EntitlementAcquisitionDate, result.EntitlementExpiryDate, result.IsExpired, result.IsTest, result.IsSiteLicense, result.Seats, result.TokenExpiryDate);

        if (result.EntitlementType.ToUpper() == "FREE")
          //Allow basic functionality
        else if (result.EntitlementType.ToUpper() == "PAID")
          //Allow all functionality
        else //trial
          //Allow limited functionality
        licVerifyEndPoint.Text = "Verification service didn't return any results";

Hope you have enjoyed this series !!