Simple Webex bot by Nest.JS

For this project i wiil show you how to start webex bot (develop by Nest.JS framework, coding with Type Script) and use AWS EC2 for running webhook server , AWS API Gateway for enable HTTPS and set up custom domain for webhook endpoint.
Preparing
- We need to have a client. To download the client, follow to the link: https://www.webex.com/downloads.html and click the download button for the Webex Teams client. Alternatively you can use the web browser client which can be found at: https://teams.webex.com.
- Then for creating the bot. We must mention To create the bot and obtain its access token, navigate to the My Apps page of your account https://developer.webex.com/my-apps select Create New App and when prompted choose the Bot type then complete the form which asks for Username / Bot Name, Bot Icon and a short description. Once submitted, you will then be given the access token.
- Now the most important part , Creating the webhook. Go to www.developer.webex.com. Select Documentation -> API Reference -> Webhooks -> Create a Webhook.
Here we specify what event we're listening out for:
Authorization Use the bot's bearer token which you copied earlier
name: Create any name for your webhook
targetUrl: https://webexbot.mycompany.com/webhook
resource: 'messages',event: 'created',filter: , Then SECRET=mycrazysecret1234
For target url you can use url from AWS API Gateway.
For secret , i recommend to set up it for better security, your secret should follow how to create password in best practise.
Prepare Infrastructure
- Launch new AWS EC2 instance ,
- AMI Image => "Ubuntu 18.04"
- VPC => you can use default vpc config.
- Subnet => you can use default subnet.
- Enable Public IP => "yes"
- Security Group => Enable SSH and TCP port 9000 from 0.0.0.0/0
- EBS Size => 8GB or grather if you want.
- Tag => not necessary. you can ignore it.
- Key pair => select your key pair for SSH to this EC2 instance.
- Create AWS API Gateway endpoint
- Go to AWS API Gateway service.
- Click create api , select REST API and click build.
- Select New API , type api name and description , select edge optimize for endpoint type.
- Go to resources , click action select create resource type "webhook" for resource name and enable api gateway cors.
- On the resource "webhook" click action select "creat methods" select "POST" type.
- Go to method request select http proxy and type "http://:9000/webhook" and save this config.

- Go to method request and add "x-spark-signature" for pass this header into webhook server in "http request header config" and select required.

- Click action and select deploy API , select stage name (if you not have stage you can create new stage) and click deploy for save all api gateway config.
- Set up custom domain name for api gateway
- Add certificate for enable https in AWS certificate manager. (if you have alreday certificate , you can use it for this project).
- Go to API gateway and select custom domain mame.
- Click create.
- Type your domain name for example "webexbot.mycompany.com".
- Select endpoint type , i suggest edge optimize type.
- Select certificate.
- Click create domain name

- Click your endpoint and map domain name with your stage

- Go to dns management for your domain and add cname record and point to api gateway endpoint from api gateway

Deploy simple code
Try to play with bot
- Open Cisco Webex Team, log in to system if need.
- Add bot to your group by type bot name.
- Type "hello" and mention with "@"
- Your should to see responce message.
- Have a fun with Webex bot !!

Reference