# feedbot-azure-function

> Template for deploying Feedbot platform instance (botbuilder bot + designer) into Azure Functions environment.

Latest version **1.8.0-alpha.3** (published 2019-05-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install feedbot-azure-function
pnpm add feedbot-azure-function
yarn add feedbot-azure-function
bun add feedbot-azure-function
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.8.0-alpha.3 |
| Published | 2019-05-30 |
| First published | 2019-02-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 17 |
| Unpacked size | 122.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Jan Dvorak |
| Maintainers | dvorakjan |

## Links

- npm: https://www.npmjs.com/package/feedbot-azure-function
- Repository: git@gitlab.com:feedyou/feedbot/template/azure-function
- npm.io page: https://npm.io/package/feedbot-azure-function

## Dependencies (17)

- [cpx](https://npm.io/package/cpx.md) ^1.5.0
- [jimp](https://npm.io/package/jimp.md) ^0.2.28
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [dotenv](https://npm.io/package/dotenv.md) ^4.0.0
- [base-64](https://npm.io/package/base-64.md) ^0.1.0
- [core-js](https://npm.io/package/core-js.md) ^3.0.1
- [express](https://npm.io/package/express.md) ^4.16.3
- [ts-node](https://npm.io/package/ts-node.md) ^7.0.1
- [winston](https://npm.io/package/winston.md) ^3.1.0
- [uglify-es](https://npm.io/package/uglify-es.md) ^3.2.2
- [typescript](https://npm.io/package/typescript.md) ^3.2.4
- [streamifier](https://npm.io/package/streamifier.md) ^0.1.1
- [azure-storage](https://npm.io/package/azure-storage.md) ^2.10.2
- [patch-package](https://npm.io/package/patch-package.md) ^5.1.1
- [azure-functions-pack](https://npm.io/package/azure-functions-pack.md) ^0.3.1
- [azure-function-express](https://npm.io/package/azure-function-express.md) ^1.3.0
- [@dvorakjan/feedbot-node-sdk](https://npm.io/package/@dvorakjan/feedbot-node-sdk.md) ^1.8.0-alpha.3

## Recent versions

- 1.8.0-alpha.3 (latest) — 2019-05-30
- 1.7.0-alpha.35 (next) — 2019-03-22
- 1.7.0-alpha.34 — 2019-03-22
- 1.7.0-alpha.33 — 2019-03-22
- 1.7.0-alpha.32 — 2019-03-22
- 1.7.0-alpha.31 — 2019-03-22
- 1.7.0-alpha.30 — 2019-03-22
- 1.7.0-alpha.29 — 2019-03-22
- 1.7.0-alpha.28 — 2019-03-21
- 1.7.0-alpha.27 — 2019-03-21
- 1.8.0-alpha.2 — 2019-03-20
- 1.8.0-alpha.1 — 2019-03-20
- 1.7.0-alpha.26 — 2019-03-18
- 1.7.0-alpha.24 — 2019-03-05
- 1.7.0-alpha.23 — 2019-03-02
- … 18 more at https://npm.io/package/feedbot-azure-function/versions

## README

# 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 `AccountName`parameter 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:

```JSON
{
  "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](https://github.com/Azure/azure-functions-core-tools) ([guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local)) 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](https://github.com/creationix/nvm/blob/master/README.md)) or `node.js` ([Installer](https://nodejs.org/en/)). For nvm use `nvm ls` to see installed node versions on your machine and `nvm use <version>` to switch to a newest version. [Guide](https://davidwalsh.name/nvm)
    - 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](https://github.com/Microsoft/BotFramework-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:

```javascript
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](https://insomnia.rest/)

### 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](https://azure.microsoft.com/en-us/features/storage-explorer/)

### Microsoft Bot Framework Emulator

 *Microsoft Bot Framework Emulator* simulates user-side interaction environment with Feedbot: [Bot Framework Emulator](https://github.com/Microsoft/BotFramework-Emulator)

---
_Source: https://npm.io/package/feedbot-azure-function · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
