Deploy your chatbot from Github

This article describes how to deploy chatbot from Github repo in 3 easy steps with Github Actions. This article assumes that you already created or cloned samples repository.

Step 1. Prepare scenario file

Chatbot scenarios can be stored as XML files, therefore they can be version-controlled and edited with your favorite code editor.

Visual Studio is a nice option
Basic chatbot scenario

You can even edit it directly on GitHub


So for start, save your scenario into the file and don't forget to add it to a repository with git add command.

Step 2. Use update_scenario endpoint.

For scenario management purposes, provides an API. This is the only API endpoint that takes a body in the form of application/xml - chatbot scenario format. To use it you need to provide a subscriptionKey, botName, and scenario like in the example below

-- CODE lang-bash -- curl -v -X PUT "" -H "Content-Type: application/xml" -H "Cache-Control: no-cache" -H "Ocp-Apim-Subscription-Key: XXXXXXXXXXXXXXXXXXXXXXXXXX" --data-raw '<bot> <states> <state name="Start"> <transition input="hello" next="Start">Hello from chatbot</transition> <transition input="*" next="Start" morphology="msg">You send me {msg}</transition> </state> </states> </bot>'

To get the subscription key you should navigate to your Profile page and copy a primary or secondary key from your current subscription

Profile page

The same REST request can be used in GitHub actions as well providing you with the ability to set up continuous development.

Step 3. Setup GitHub actions for chatbot

GitHub Actions allows you to set up a workflow for CI/CD with simple to understand .yaml files. We already prepared a template for chatbot deployment in our sample-scenarios repository. To use it add your own copy of the workflow file to .github/workflows folder of your repository.

Workflow template

-- CODE lang-yaml -- name: Bot Deploy # Controls when the action will run. on: # Triggers the workflow on push or pull request events but only for the main branch push: branches: [ main ] pull_request: branches: [ main ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: deploy: # The type of runner that the job will run on runs-on: ubuntu-latest steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - name: Set demoBot scenario from repository env: SUB_KEY: ${{ secrets.SubscriptionKey }} BOT_NAME: "demoBot" BOT_FILE: ./default.xml run: > curl -v -X PUT "$BOT_NAME/scenario" -H "Content-Type: application/xml" -H "Cache-Control: no-cache" -H "Ocp-Apim-Subscription-Key: $SUB_KEY" --data @$BOT_FILE

This workflow will set up an ubuntu machine and will deploy a chatbot with a CURL command from a file. Don't forget to change env variables SUB_KEY, BOT_NAME, BOT_FILE of your account and repository to your own.

Don't miss these stories: