Run (Teletype)

app.lib.run(func, action='') is used to execute code following a run command from Teletype. It takes the function to be executed and the name of the action to trigger the function.

Arguments

  • func: Function function to be executed when action is passed to the run command from Teletype.
  • action: String name of the action to trigger func.


Usage example:

const { app } = require('detalib');

app.lib.run(event => 'Willkommen in Berlin.');
app.lib.run(event => 'Willkommen in Kreuzberg!', 'kreuzberg');
app.lib.run(event => 'Willkommen in Steglitz!', 'steglitz');

module.exports = app;


Command (Teletype)

run

Response

'Wilkommen in Berlin!';


Command (Teletype Studio)

run kreuzberg

Response

'Wilkommen in Kreuzberg!';


You can also stack run and cron together.

const { app } = require('detalib');

const printTime = event => `it is ${(new Date).toTimeString()}`

app.lib.run(printTime, 'time');
app.lib.cron(printTime);

module.exports = app;

event attributes

  • event.json: Object provides the JSON payload as an object.
  • event.body: String provides the raw JSON payload.
  • event.type: String will be instantiated to 'run'.
  • event.action: String bears the action provided by the user or an empty string if no action is provided.