Bot settings
Set environment variables from Web interface that can be read from your bot datastore
Meya reserves a special key _settings
in your bot
scope database to store settings from the Meya Web IDE.
Use-cases
- store API keys and urls
- differentiate development from production environments
- store global UX variables like default delay timings
- credentials to access restricted resources
- reuse bot code in multiple bots, adapted with settings
- have non-technical roles adjust basic bot settings w/o touching code
Writing settings
You can find the settings from Dashboard > Bot > Settings
. You can can specify any data using YAML syntax: strings, integers, floats, booleans, lists and objects.
Reading settings
You can read from settings in BFML using mustache syntax {{ bot._settings.key }}
or from Python components using self.db.bot.settings["key"]
See lines 6, 8 in BFML below.
states:
timezone:
component: meya.text
properties:
text: "Your bot is configured in the {{ bot._settings.timezone }}"
delay:
relative: "{{ bot._settings.short_delay }}"
register:
component: register
properties:
data:
age: 53
name: "Michelle Obama"
done:
component: meya.text
properties:
text: "That was cool. 😎"
See lines 11, 12 in the following Python component.
from meya import Component
import requests
from requests.auth import HTTPBasicAuth
class Register(Component):
"""Register some data with API"""
def start(self):
# read url and api key from bot settings
api_url = self.db.bot.settings["api_url"]
api_key = self.db.bot.settings["api_key"]
auth = HTTPBasicAuth(api_key, "")
# read data from properties
data = self.properties.get('data') or {}
# make the request
print requests.post(api_url, json=data, auth=auth).json()
# output confirmation
message = self.create_message(text="Done.")
return self.respond(message=message, action="next")
Updated over 6 years ago