DEV Community

Hemaprakash Raghu
Hemaprakash Raghu

Posted on

ProgramBuddy - Helper Bot to create project (rest-api)

Send messages in WhatsApp and get your project started right away.

GitHub Repo

Overview 🤖

The main focus is about stop doing the work which does not require much thinking and following the procedures would get the work done. Here the ideology is to work with rest apis using javascript. How great it would be when we just ask a person to create a project with standard CRUD apis and then give it to us in a way we can add more functions to it.

What I used to built 🛠

  • Amazon Lex
  • Amazon Lambda
  • Amazon S3 Bucket
  • Amazon Dynamo DB
  • Amazon Simple Email As Service
  • Twilio

The Bot

Creating the required Intents for project creation, capturing the model information and exporting the project. This bot is focusing mostly on a nodejs express project with mongodb as database.

Amazon Lex is used for the bot creation and training, with four intents as mentioned which is connected to Amazon Lambda triggered at the moment of fulfilment of each intent. Slots are used to get the required information on each intent.

Intent 01: (ProjectCreation)
Slots (Name, EmailAddress, Framework, ProjectName). These information are used as an high level for the project where used to create all configuration files.

Intent 01

Intent 02: (CapturingModel)
Slots (ModelName, ModelProperties) These information are used to create as much models we need (reusable intent)

Intent 02

Intent 03: (ExportingProject)
Used to export the files and folders based on the information saved.

Lambda Function ⚡️

It plays a major role here to process all the data from the chatbot and have a copy in the Amazon Dynamo DB to make use later. Python environment is used to extract and process and create necessary files and folders and save it to Amazon S3 bucket.

View Lambda Function

ProjectCreation Intent Extraction

if intent_name == 'ProjectCreation':
        payload = {
            "sessionId": event["sessionId"],
            "name": get_slot(event, 'Name'),
            "email": get_slot(event, 'EmailAddress'),
            "project_name": get_slot(event, 'ProjectName'),
            "framework": get_slot(event, 'Framework')
        }
        # save to dynamodb
        projectTable.put_item(Item=payload)
Enter fullscreen mode Exit fullscreen mode

CapturingModel Intent Extraction

if intent_name == 'CapturingModel':
        properties = get_slot(event, 'ModelProperties')
        name = get_slot(event, 'ModelName')
        if properties is not None:
            props_array = properties.split(',')
            sessionUser = projectTable.get_item(Key={'sessionId':event['sessionId']})
            # save to dynamodb
            schemaTable.put_item(Item={
                'sessionId':event['sessionId'],
                'model_name':name,
                'properties':props_array,
                'username':sessionUser['Item']['name']
            })
Enter fullscreen mode Exit fullscreen mode

ExportingProject Intent Extraction

if intent_name == 'ExportProject':
        sessionId = event['sessionId']
        projectInformation = projectTable.get_item(Key={'sessionId':sessionId})
        models = schemaTable.scan(
            FilterExpression='sessionId = :sId',
            ExpressionAttributeValues={":sId": sessionId}
        )
        # creating package json file
        buildPackageFile(projectInformation['Item'])
        # creating db and configuration files and folders
        createRequiredFiles(projectInformation['Item'])
        # creating router files
        createRouterFiles(projectInformation['Item'], models['Items'])
        # creating app.js file
        createMainFile(projectInformation['Item'], models['Items'])
        # zip the files and folder
        url = createZipFileStream('program-buddy', projectInformation['Item']['name']+"/"+projectInformation["Item"]['sessionId'], projectInformation['Item']['project_name'], True)
        sendEmail(projectInformation['Item'], url)

Enter fullscreen mode Exit fullscreen mode

Storing the Data 📦

Dynamo DB is used to store intermediate data which is used along during exporting the project.

# Project Information
{
 sessionId: "BOT_SESSION_ID",
 name: "USERNAME",
 email: "USER_EMAIL",
 project_name: "PROJECT_NAME",
 framework: "PROJECT_FRAMEWORK_NAME"
}
# Schema Information
{
 sessionId: "BOT_SESSION_ID",
 username: "USERNAME",
 properties: ["Item1", "Item2", "Item3"],
 model_name: "SCHEMA_NAME"
}
Enter fullscreen mode Exit fullscreen mode

Exporting the Project

Export intent is triggered and required files and folder for the project are created in lambda and then stored in s3 bucket. These files are then zipped and sent to the recipient email address using Amazon SES.
This email contains the S3 pre-signed URL to download the zipped project files.

Download Example Exported Project

Project File Sent to email

Top comments (0)