|
| 1 | +--- |
| 2 | +title: Application Environment Variables |
| 3 | +hidden: false |
| 4 | +--- |
| 5 | + |
| 6 | +## Background |
| 7 | +Application Environment Variables (app-env vars) are a feature in Jambonz that allows you to pass custom values to your application in the call webhook. |
| 8 | +This allows for you to have one instance of your application running but pass in specific customisation parameters with the call, it also allows us to offer the [Hosted Applications] |
| 9 | +with users supplying their own parameters to the application. |
| 10 | + |
| 11 | + |
| 12 | +The parameters are discovered by jambonz when you setup the call webhook and then the WebUI will create additional fields based on the schema that is returned. |
| 13 | + |
| 14 | +The values for the parameters are then entered during application setup and stored encrypted in the database. |
| 15 | + |
| 16 | +When a call is routed to the application these parameters are sent in the calling webhook. |
| 17 | + |
| 18 | +## Discovery |
| 19 | +Whenever a user creates a new calling webhook in the jambonz webUI (either webhook or websocket) jambons will make an HTTP OPTIONS request to that endpoint, |
| 20 | +If the application offers App-Env Vars it should respond with a JSON schema defining these parameters. |
| 21 | + |
| 22 | +If the application does not respond with a valid JSON schema or does not handle the OPTIONS request then Jambonz will silently ignore the error and the application configuration can continue as normal. |
| 23 | + |
| 24 | +## Schema |
| 25 | +The schema is a JSON object, with each parameter name as a key and then an object containing the attributes of that parameter. |
| 26 | +For example the below schema would define a parameter of `NAME` as a `string` type that is not required, and has a description |
| 27 | + |
| 28 | +```JSON |
| 29 | +{ |
| 30 | + "NAME": { |
| 31 | + "description": "Your Name", |
| 32 | + "type": "string", |
| 33 | + "required": true, |
| 34 | + "default": "Bob", |
| 35 | + "obscure": false, |
| 36 | + "uiHint": "input" |
| 37 | + } |
| 38 | + |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +A schema can contain multiple parameters, but each one must have a unique name. |
| 43 | + |
| 44 | +### Attributes |
| 45 | +The following attributes can be defined for a parameter in the schema |
| 46 | + |
| 47 | +<ParamField path="description" type="string" required={true}> |
| 48 | + A description of the parameter, this will be visible to the user when then mouseover the ? icon next to the parameter in the UI |
| 49 | +</ParamField> |
| 50 | + |
| 51 | +<ParamField path="type" type="string" required={true}> |
| 52 | +One of: |
| 53 | +- `string` |
| 54 | +- `boolean` |
| 55 | +- `number` |
| 56 | + The type of parameter, this is how the parameter will be sent in the callHook so a number would be sent as `5` whereas a string would be sent as `"5"` |
| 57 | +</ParamField> |
| 58 | + |
| 59 | +<ParamField path="required" type="boolean" required={false}> |
| 60 | +If set to True then the parameter must be defined in order for the application to be created |
| 61 | +</ParamField> |
| 62 | + |
| 63 | +<ParamField path="default" type="string|number|boolean" required={false}> |
| 64 | +A default value to pre-fill for the parameter |
| 65 | +</ParamField> |
| 66 | + |
| 67 | +<ParamField path="enum" type="array" required={false}> |
| 68 | +An array of values, if set then the UI will show a dropdown asking the user to select a value. |
| 69 | +</ParamField> |
| 70 | + |
| 71 | +<ParamField path="obscure" type="boolean" required={false}> |
| 72 | +If set then the value will be obscured in the UI, useful for passwords and API keys. |
| 73 | +</ParamField> |
| 74 | + |
| 75 | +<ParamField path="uiHint" type="string" required={false}> |
| 76 | +One of: |
| 77 | +- `input` |
| 78 | +- `textarea` |
| 79 | +- `filepicker` |
| 80 | +When type is set to string the default is a simple one line text box, `textarea` allows for a larger multiline input |
| 81 | +and `filepicker` will allow the user to upload a text file directly into the textarea. All values are still stored and passed as a string. |
| 82 | +</ParamField> |
| 83 | + |
| 84 | +## Call Hook |
| 85 | + |
| 86 | +Once an application has been created with its app-env vars defined and stored when a call is made either inbound or outbound these values |
| 87 | +will be added to the callHook as a new object under the `env-vars` key. |
| 88 | +They are only sent on the initial callHook not on any subsequent hooks or on the call Status hook. |
| 89 | + |
| 90 | +## API |
| 91 | + |
| 92 | +App Env Vars may also be created, read and modified on an application via the [REST API](/reference/rest-platform-management/applications/create-application#request.body.env_vars) |
| 93 | + |
| 94 | +You can also invoke the OPTIONS request to fetch a scheme from an endpoint using the [API](http://127.0.0.1:3002/reference/rest-platform-management/applications/get-app-env-schema) |
0 commit comments