跳至主要内容

取值介紹

在 Asgard 工作流程中,設定值支援三種取值方式:Literal(常數)Expression(表達式)Template(模板)

取值方式

Literal(常數)

固定不變的內容。

語法範例:

歡迎使用我們的服務!

Expression(表達式)

使用 JavaScript 表達式進行動態運算和邏輯處理。

語法範例:

// 直接對變數取值
prevMessage

// 使用布林表達式取值
userName || '訪客'

// 呼叫內建函數取得回傳值
history(0, -1)

// 呼叫內建函數取得回傳值
urlEncode(searchKeyword)

Template(模板)

使用 Handlebars 語法進行模板渲染。

語法範例:

{{#each prevBlobs}}
檔案
{{@index}}:
{{fileName}}
{{#if (eq fileType 'IMAGE')}}
圖片檔案:{{mime}}
{{/if}}
{{/each}}

內建資源

內建變數

  • 對話相關prevMessageprevBlobsprevPayloadprevError
  • 頻道相關customChannelIdcustomMessageId

詳細說明請參考 Expression 變數

內建函數

提供 8 個專用內建函數:

  • 對話歷史history()historySize()
  • 資料處理urlEncode()vecToStr()xpathExtract()
  • 日期時間isoNow()isoToday()

詳細說明請參考 Expression 內建函數

範例

Expression 模式

// 基本變數使用
prevMessage || '無訊息'

// 邏輯判斷
prevError ? `錯誤:${prevError}` : '處理正常'

// 函數調用
`對話記錄:${historySize()}`

Template 模式

{{#if prevMessage}}
您剛才說:{{prevMessage}}
{{else}}
歡迎開始對話!
{{/if}}

當前時間:{{{isoNow 'Asia/Taipei'}}}