1. Learn center
  2. Software development
  3. How-tos
  4. How to create a Typetalk bot to deploy your application

How to create a Typetalk bot to deploy your application

Typetalk Staff

Typetalk Staff

January 31, 2018

There’s enough to think about when deploying your application. Why not make the process simple and transparent by deploying through Typetalk?

With this tutorial, we’ll show you how to create a bot you can tell to deploy your application, simultaneously informing your entire team of the update.

How to create a deployment bot for Typetalk

For this tutorial, we will use the following services:

And we will use the below architecture:

deploy bot architecture


1. Set your Lambda function

First, create the following two functions on AWS Lambda.

Function #1

Function 1

This function will accept the request from the API Gateway, parse the response body, and then create the deployment on CodeDeploy.

var AWS = require('aws-sdk');
var codedeploy = new AWS.CodeDeploy({ region: process.env.YOUR_CODEDEPLOY_REGION });

exports.handler = function(event, context, callback) {
  var params = {
    applicationName: process.env.YOUR_CODEDEPLOY_APPLICATION_NAME,
    deploymentGroupName: process.env.YOUR_CODEDEPLOY_DEPLOYMENT_GROUP_NAME,
    revision: {
      revisionType: "S3",
      s3Location: {
        bucket: process.env.YOUR_BUCKET,
        bundleType: process.env.YOUR_BUNDLE_TYPE,
        eTag: process.env.YOUR_BUCKET_ETAG,
        key: process.env.YOUR_BUCKET_KEY,
        version: process.env.YOUR_BUCKET_VERSION

  codedeploy.createDeployment(params, function(err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else console.log(data); // successful response

  var body = JSON.parse(event.body);
  var id = body.post.id;

  var responseBody = {
    "message": "Deployment has been started...",
    "replyTo": id
  var response = {
    "statusCode": 200,
    "headers": {},
    "body": JSON.stringify(responseBody),
    "isBase64Encoded": false

  callback(null, response);

Function #2

Function 2

This function will post a message to Typetalk.

var exec = require('child_process').exec;

exports.handler = (event, context, callback) => {
  var url = "'https://typetalk.com/api/v1/topics/" + process.env.YOUR_TOPIC_ID + "?typetalkToken=" + process.env.YOUR_TYPETALK_TOKEN + "'";
  var cmd = "curl --data-urlencode 'message=Deployment has been finished!' " + url;
  exec(cmd, function(err, stdout, stderr){

  callback(null, 'Message has been posted');

2. Set your API Gateway

Next, create an API Gateway to accept the Webhook from Typetalk.
You will need to create a POST method for our API and connect it to the Lambda function #1.

set your API gateway

After deploying it, check and note the “Invoke URL”. You will use it for the Webhook request.

invoke URL

3. Set your SNS Topic

Next, create an SNS Topic to connect to your CodeDeploy application and the Lambda function #2.

create sns topic

After creating the SNS Topic, connect it to your CodeDeploy application.

create trigger

4. Create your Typetalk bot

Next, create your bot on Typetalk. The deploy bot will post messages and send Webhook requests, so you’ll need to check “API Scope > topic.post” and “Webhook > Use Webhook”.

Also, you need to specify the URL the bot will send Webhooks to. The URL should be the API Gateway endpoint you created in step 2.

create bot

5. Deploy your application

Finally, you’re ready to deploy! Ask your bot to deploy your application by posting a mention to the bot. The bot will reply when complete.

deploy app

After receiving the message from your bot, deployment will begin.

deploy in progress

And it will post a message again when deployment has succeeded.

deploy success

All members of the assigned Typetalk topic can see the status of deployment, keeping your whole team informed.

bot complete

Rather than using your console while having to tell your team that you’re deploying, combine these steps into one simple Typetalk message to your bot. Deploying has never been easier!


Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life