Options
All
  • Public
  • Public/Protected
  • All
Menu

Module script

Script Module

Control conversation flow with programming language styled script.

Install

npm install @sociably/core @sociably/http @sociably/script
# or with yarn
yarn add @sociably/core @sociably/http @sociably/script

Docs

Check the Dialog Script document and the package reference.

Setup

Register the built script like this:

import Sociably from '@sociably/core';
import Script from '@sociably/script';
import BeforeSunrise from './scenes/BeforeSunset';
import BeforeSunset from './scenes/BeforeSunset';
import BeforeMidnight from './scenes/BeforeSunset';

const app = Sociably.createApp({
modules: [
Script.initModule({
libs: [
BeforeSunrise,
BeforeSunset,
BeforeMidnight,
],
}),
],
});

Index

Keyword Element

CallElement<Vars, Script>: SociablyElement<CallProps<Vars, Script>, typeof CALL>

Type parameters

EffectElement<Vars, Yield>: SociablyElement<EffectProps<Vars, Yield>, typeof EFFECT>

Type parameters

  • Vars

  • Yield

ElseElement<Vars, Input, Return, Yield>: SociablyElement<BlockProps<Vars, Input, Return, Yield>, typeof ELSE>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

ElseIfElement<Vars, Input, Return, Yield>: SociablyElement<ElseIfProps<Vars, Input, Return, Yield>, typeof ELSE_IF>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

IfElement<Vars, Input, Return, Yield>: SociablyElement<IfProps<Vars, Input, Return, Yield>, typeof IF>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

LabelElement: SociablyElement<LabelProps, typeof LABEL>
PromptElement<Vars, Input>: SociablyElement<PromptProps<Vars, Input>, typeof PROMPT>

Type parameters

  • Vars

  • Input

ReturnElement<Vars, Return>: SociablyElement<ReturnProps<Vars, Return>, typeof RETURN>

Type parameters

  • Vars

  • Return

ThenElement<Vars, Input, Return, Yield>: SociablyElement<BlockProps<Vars, Input, Return, Yield>, typeof THEN>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

WhileElement<Vars, Input, Return, Yield>: SociablyElement<WhileProps<Vars, Input, Return, Yield>, typeof WHILE>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

Keyword Props

BlockProps<Vars, Input, Return, Yield>: { children: ScriptNode<Vars, Input, Return, Yield> }

Type parameters

  • Vars

  • Input

  • Return

  • Yield

Type declaration

CallProps<Vars, Script>: Script extends ScriptLibrary<unknown, unknown, infer Params, infer Return, unknown> ? { goto?: string; key: string; params?: CallParamsGetter<Vars, Params>; script: Script; set?: CallReturnSetter<Vars, Return> } : never

Type parameters

EffectProps<Vars, Yield>: { set?: EffectSetter<Vars>; yield?: EffectYielder<Vars, Yield> }

Type parameters

  • Vars

  • Yield

Type declaration

ElseIfProps<Vars, Input, Return, Yield>: { children: ScriptNode<Vars, Input, Return, Yield>; condition: ConditionMatcher<Vars> }

Type parameters

  • Vars

  • Input

  • Return

  • Yield

Type declaration

IfProps<Vars, Input, Return, Yield>: { children: ConditionBlocks<Vars, Input, Return, Yield> | ConditionBlocks<Vars, Input, Return, Yield>[]; condition: ConditionMatcher<Vars> }

Type parameters

  • Vars

  • Input

  • Return

  • Yield

Type declaration

  • children: ConditionBlocks<Vars, Input, Return, Yield> | ConditionBlocks<Vars, Input, Return, Yield>[]
  • condition: ConditionMatcher<Vars>
LabelProps: { key: string }

Type declaration

  • key: string
PromptProps<Vars, Input>: { key: string; set?: PromptSetter<Vars, Input> }

Type parameters

  • Vars

  • Input

Type declaration

ReturnProps<Vars, Return>: { value?: ReturnValueGetter<Vars, Return> }

Type parameters

  • Vars

  • Return

Type declaration

WhileProps<Vars, Input, Return, Yield>: { children: ScriptNode<Vars, Input, Return, Yield>; condition: ConditionMatcher<Vars> }

Type parameters

  • Vars

  • Input

  • Return

  • Yield

Type declaration

Other

AnyScriptLibrary: ScriptLibrary<any, any, any, any, any>
CallCommand<Vars, Params, Return, Yield>: { goto?: string; key: string; script: ScriptLibrary<unknown, unknown, Params, Return, Yield>; setVars?: CallReturnSetter<Vars, Return>; type: "call"; withParams?: CallParamsGetter<Vars, Params> }

Type parameters

  • Vars

  • Params

  • Return

  • Yield

Type declaration

CallParamsFn<Vars, Params>: (circs: ScriptCircs<Vars>) => Params | Promise<Params>

Type parameters

  • Vars

  • Params

Type declaration

    • Parameters

      Returns Params | Promise<Params>

CallParamsGetter<Vars, Params>: MaybeContainer<CallParamsFn<Vars, Params>>

Type parameters

  • Vars

  • Params

CallReturnSetFn<Vars, Return>: (circs: ScriptCircs<Vars>, returnValue: Return) => Vars | Promise<Vars>

Type parameters

  • Vars

  • Return

Type declaration

    • (circs: ScriptCircs<Vars>, returnValue: Return): Vars | Promise<Vars>
    • Parameters

      Returns Vars | Promise<Vars>

CallReturnSetter<Vars, Return>: MaybeContainer<CallReturnSetFn<Vars, Return>>

Type parameters

  • Vars

  • Return

CallStatus<Vars>: { script: ScriptLibrary<Vars, unknown, unknown, unknown, unknown>; stopAt: undefined | string; vars: Vars }

Type parameters

  • Vars

Type declaration

  • script: ScriptLibrary<Vars, unknown, unknown, unknown, unknown>
  • stopAt: undefined | string
  • vars: Vars
ConditionMatchFn<Vars>: (circs: ScriptCircs<Vars>) => boolean | Promise<boolean>

Type parameters

  • Vars

Type declaration

    • Parameters

      Returns boolean | Promise<boolean>

ConditionMatcher<Vars>: MaybeContainer<ConditionMatchFn<Vars>>

Type parameters

  • Vars

ConditionsSegment<Vars>: { branches: { body: ScriptSegment<Vars, unknown, unknown, unknown>[]; condition: ConditionMatcher<Vars> }[]; fallbackBody: null | ScriptSegment<Vars, unknown, unknown, unknown>[]; type: "conditions" }

Type parameters

  • Vars

Type declaration

ContentCommand<Vars>: { getContent: ContentNode<Vars>; type: "content" }

Type parameters

  • Vars

Type declaration

ContentFn<Vars>: (circs: ScriptCircs<Vars>) => SociablyNode | Promise<SociablyNode>

Type parameters

  • Vars

Type declaration

ContentNode<Vars>: MaybeContainer<ContentFn<Vars>>

Type parameters

  • Vars

EffectCommand<Vars, Yield>: { setVars?: EffectSetter<Vars>; type: "effect"; yieldValue?: EffectYielder<Vars, Yield> }

Type parameters

  • Vars

  • Yield

Type declaration

EffectSetFn<Vars>: (circs: ScriptCircs<Vars>) => Vars | Promise<Vars>

Type parameters

  • Vars

Type declaration

    • Parameters

      Returns Vars | Promise<Vars>

EffectSetter<Vars>: MaybeContainer<EffectSetFn<Vars>>

Type parameters

  • Vars

EffectYieldFn<Vars, Yield>: (circs: ScriptCircs<Vars>, prevValue: undefined | Yield) => Yield | Promise<Yield>

Type parameters

  • Vars

  • Yield

Type declaration

    • (circs: ScriptCircs<Vars>, prevValue: undefined | Yield): Yield | Promise<Yield>
    • Parameters

      Returns Yield | Promise<Yield>

EffectYielder<Vars, Yield>: MaybeContainer<EffectYieldFn<Vars, Yield>>

Type parameters

  • Vars

  • Yield

InputOfScript<Script>: Script extends ScriptLibrary<unknown, infer Input, unknown, unknown, unknown> ? Input : never

Type parameters

JumpCommand: { offset: number; type: "jump" }

Type declaration

  • offset: number
  • type: "jump"
JumpCondCommand<Vars>: { condition: ConditionMatcher<Vars>; isNot: boolean; offset: number; type: "jump_cond" }

Type parameters

  • Vars

Type declaration

LabelSegment: { key: string; type: "label" }

Type declaration

  • key: string
  • type: "label"
ParamsOfScript<Script>: Script extends ScriptLibrary<unknown, unknown, infer Params, unknown, unknown> ? Params : never

Type parameters

PromptCommand<Vars, Input>: { key: string; setVars?: PromptSetter<Vars, Input>; type: "prompt" }

Type parameters

  • Vars

  • Input

Type declaration

  • key: string
  • Optional setVars?: PromptSetter<Vars, Input>
  • type: "prompt"
PromptSetFn<Vars, Input>: (circs: ScriptCircs<Vars>, input: Input) => Vars | Promise<Vars>

Type parameters

  • Vars

  • Input

Type declaration

    • (circs: ScriptCircs<Vars>, input: Input): Vars | Promise<Vars>
    • Parameters

      Returns Vars | Promise<Vars>

PromptSetter<Vars, Input>: MaybeContainer<PromptSetFn<Vars, Input>>

Type parameters

  • Vars

  • Input

ReturnCommand<Vars, Return>: { getValue?: ReturnValueGetter<Vars, Return>; type: "return" }

Type parameters

  • Vars

  • Return

Type declaration

ReturnOfScript<Script>: Script extends ScriptLibrary<unknown, unknown, unknown, infer Return, unknown> ? Return : never

Type parameters

ReturnValueFn<Vars, Return>: (circs: ScriptCircs<Vars>) => Return | Promise<Return>

Type parameters

  • Vars

  • Return

Type declaration

    • Parameters

      Returns Return | Promise<Return>

ReturnValueGetter<Vars, Return>: MaybeContainer<ReturnValueFn<Vars, Return>>

Type parameters

  • Vars

  • Return

ScriptCircs<Vars>: { channel: SociablyChannel; platform: string; vars: Vars }

Type parameters

  • Vars

Type declaration

ScriptCommand<Vars, Input, Return, Yield>: ContentCommand<Vars> | JumpCommand | JumpCondCommand<Vars> | PromptCommand<Vars, Input> | CallCommand<Vars, unknown, unknown, Yield> | EffectCommand<Vars, Yield> | ReturnCommand<Vars, Return>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

ScriptElement<Vars, Input, Return, Yield>: IfElement<Vars, Input, Return, Yield> | WhileElement<Vars, Input, Return, Yield> | PromptElement<Vars, Input> | LabelElement | CallElement<Vars, AnyScriptLibrary> | ReturnElement<Vars, Return>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

ScriptLibrary<Vars, Input, Params, Return, Yield>: { $$typeof: typeof SOCIABLY_SCRIPT_TYPE; Start: ContainerComponent<StartScriptProps<Params>>; commands: ScriptCommand<Vars, Input, Return, Yield>[]; name: string; stopPointIndex: Map<string, number>; initVars: any }

Type parameters

  • Vars

  • Input

  • Params

  • Return

  • Yield

Type declaration

  • $$typeof: typeof SOCIABLY_SCRIPT_TYPE
  • Start: ContainerComponent<StartScriptProps<Params>>
  • commands: ScriptCommand<Vars, Input, Return, Yield>[]
  • name: string
  • stopPointIndex: Map<string, number>
  • initVars:function
    • initVars(params: Params): Vars
ScriptNode<Vars, Input, Return, Yield>: SociablyEmpty | ContentNode<Vars> | ScriptElement<Vars, Input, Return, Yield> | ScriptNode<Vars, Input, Return, Yield>[] | SociablyElement<{ children: ScriptNode<Vars, Input, Return, Yield> }, typeof Fragment>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

ScriptProcessState: { callStack: SerializedCallStatus<unknown>[]; timestamp: number; version: "0" }

Type declaration

ScriptSegment<Vars, Input, Return, Yield>: ContentCommand<Vars> | ConditionsSegment<Vars> | WhileSegment<Vars> | PromptCommand<Vars, Input> | CallCommand<Vars, unknown, unknown, Yield> | EffectCommand<Vars, Yield> | LabelSegment | ReturnCommand<Vars, Return>

Type parameters

  • Vars

  • Input

  • Return

  • Yield

SerializedCallStatus<Vars>: { name: string; stopAt: string; vars: Vars }

Type parameters

  • Vars

Type declaration

  • name: string
  • stopAt: string
  • vars: Vars
VarsOfScript<Script>: Script extends ScriptLibrary<infer Vars, unknown, unknown, unknown, unknown> ? Vars : never

Type parameters

WhileSegment<Vars>: { body: ScriptSegment<Vars, unknown, unknown, unknown>[]; condition: ConditionMatcher<Vars>; type: "while" }

Type parameters

  • Vars

Type declaration

YieldOfScript<Script>: Script extends ScriptLibrary<unknown, unknown, unknown, unknown, infer Yield> ? Yield : never

Type parameters

  • build<Vars, Input, Params, Return, Yield>(options: ScriptBuildOtions<Params, Vars>, src: SociablyElement<unknown, unknown>): ScriptLibrary<Vars, Input, Params, Return, Yield>

Generated using TypeDoc