1.8.0-alpha.3 • Published 5 years ago

feedbot-azure-function v1.8.0-alpha.3

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
5 years ago

Feedbot Azure Function

This repo is skeleton used for development of Feedbot and its deployment into the Azure Function environment. Its split into three separate functions, each of them with its own API:

  • messages is the main botbuilder messaging endpoint which is wrapped by the feedbot-node-sdk (it is bootstrapped and configured using env variables in messages/index.js file)
  • management is custom API determined for non-messaging calls of Feedbot (mainly from Designer), for example:
    • get current version of bot tree
    • push new version of bot tree
    • get users handoff state
    • trigger some user's handoff
  • file-upload is custom API for uploading images (encoded to base64) to azure blob storage.
    • optional parameters: http://localhost:7071/api/file-upload/{filename?}/{thumbnail?}/{thumbnailHeight?}
    • if BlobAccountUrl environment variable is set, then POST response will return image url based on this variable.
    • if BlobAccountUrl is not set, then AzureWebJobsStorage will be automatically parsed for AccountNameparameter and custom image url returned.

      don't forget to set AzureWebJobsStorage in local.settings.json file too

  • proactive-messages is default botbuilder Proactive template's function for proactive messaging (when bot wants to send message to user by its own using Azure Storage Queue - for example when some long duration processing is finished)

Setup

Following setup includes preparing your workspace for working with Azure Functions in production environment. Development environment works without this step.

  • create local.settings.json file and paste the following:
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "NODE_OPTIONS": "--inspect=5858"
  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "*"
  },
  "ConnectionStrings": {
    "SQLConnectionString": "Value"
  }
}

Development

There are two ways how to run azure-function locally:

  1. npm start - uses ts-node and nodemon to run messages/index.js endpoint only in a development environment with automatic restart on source file changes.

  2. npm run func - uses a simulated Azure Functions environment to run all functions in parallel in a production environment

    • install azure-functions-core-tools (guide) globally first (on Mac need to force version using npm i -g azure-functions-core-tools@2.0.1-beta.21)
    • update Node.js to the new version. You can use nvm - Node Version Manager (Installer) or node.js (Installer). For nvm use nvm ls to see installed node versions on your machine and nvm use <version> to switch to a newest version. Guide
    • in case of Missing value for AzureWebJobsStorage in local.settings.json error, change extension of file proactive-messages/function.json to something else temporarily OR just add AzureWebJobsStorage value in packages/azure-storage/local.settings.json.

Both of these scripts start bot instance on localhost:7071/api/messages and you can use Bot Framework Emulator to test it's behavior which is loaded from messages/tree/default.json (or "FeedbotTreeFile" environment variable).

To emulate Azure Storage environment, .env file needs to configure one setting:

  • create .env file at the root of the azure-functions folder and insert the following:

    AzureWebJobsStorage="UseDevelopmentStorage=true"

Deployment

Deploying new Feedbot instance is described in wearefeedyou/feedbot wiki

Configuration

You can configure the behaviour of chatbot with several environment variables, defined in .env file:

NODE_ENV="development" //options: [ "development", "production" ]
FeedbotTreeFile="default" //points to azure-function/messages/tree/default.json
port=7071 //port for express to listen to

AzureWebJobsStorage="UseDevelopmentStorage=true" //azure-storage account string

FeedbotTestModeEmailRecipient="myemail@gmail.com" //email address to send emails to

// result storage related items:
ResultStorageExcelSpreadsheetId="1234567890"
ResultStorageExcelSheetName="List1"
ResultStorageClientId="1234567890"
ResultStorageClientSecret="abcd1234"
ResultStorageRefreshToken="abcdefghij1234567890"
ResultStorageSuccessFactorsCompanyUsername="User"
ResultStorageSuccessFactorsCompanyPassword="Password"
ResultStorageSuccessFactorsCompanyId="Company"

// www.Amio.io related items:
AmioChannelId1="1234567890"
AmioSecret1="abcd1234"
amioAccessToken="abcdefghij1234567890"
QuickReplyImageUrl="http://tny.im/i4e" //image for QuickReply button for Facebook

// www.Teamio.com related items:
TeamioLogin="User"
TeamioPassword="Password"

Tools

Insomnia

Insomnia is used for making requests to REST APIs: Insomnia REST Client

Microsoft Azure Storage Explorer

Microsoft Azure Storage Explorer is used for tracking table/blob/queue storage values in the azure-storage database: Microsoft Azure Storage Explorer

Microsoft Bot Framework Emulator

Microsoft Bot Framework Emulator simulates user-side interaction environment with Feedbot: Bot Framework Emulator