Stella Platform Documentation

Stella Platform Documentation

  • Docs
  • Procedures
  • Reference
  • FAQ
  • Bot API
  • API
  • Languages iconEnglish
    • 中文

Action

How do I apply my API to Stella?

Stella is a highly customizable bot building tool and provides the flexibility to build a personalized chatbot flow for any business use case. You can make use of actions in Stella, which includes both Pre-actions and Post-actions.

Please refer to the sample code below on fetching data from JSON placeholder.

The sample code logic is as follows:

  1. Stella has a specific syntax for actions. You must return a new promise and resolve it at last.
  2. Assume the chatbot has asked the customers their user ID, the chatbot will then get the questions answer(user's ID) from customer and save it as a constant in Javascript
  3. Fetch data from JSON placeholder. Stella is using node-fetch npm package in here.
  4. Assign user data to this.member with this.lodash.set
  5. Update this.member through the use of resolve
return new Promise((resolve) => {
  const userId = this.messageEvent.data.text
  
  const userInfo = fetch(`https:\/\/jsonplaceholder.typicode.com/users/${userId}`)
    .then(res => res.json())
  
  this.lodash.set(this.member, "botMeta.tempData.userInfo", userInfo)
  
  resolve({
    member: this.member
  })
})

For later usage, you can access the to-dos data with this.lodash.get(this.member, "botMeta.tempData.userInfo", null).

  • How do I apply my API to Stella?
Stella Platform Documentation
Docs
Get StartedBot API ReferenceAPI ReferenceStandard Procedures
Community
FAQUser ShowcaseChat with Us
Copyright © 2021 Sanuker Inc. Limited