How to use @botonic/core - 10 common examples

To help you get started, we’ve selected a few @botonic/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hubtype / botonic / packages / botonic-cli / templates / handoff / src / actions / transfer-agent.js View on Github external
static async botonicInit({ input, session, params, lastRoutePath }) {
    /*
      Uncomment the lines below before deploying the bot to Hubtype
      in order to test the getOpenQueues call for 'Customer Support'.
    */
    // let openQueues = await getOpenQueues(session)
    let agentEmail = ''
    try {
      agentEmail = (await getAvailableAgents(
        session,
        'HUBTYPE_DESK_QUEUE_ID'
      )).filter(agent => agent == 'agent-name@hubtype.com')[0]
    } catch (e) {}

    let isHandOff = false
    // if (openQueues.queues.indexOf('Customer Support') !== -1) {
    let handOffBuilder = new HandOffBuilder(session)
    handOffBuilder.withQueue('HUBTYPE_DESK_QUEUE_ID')
    handOffBuilder.withAgentEmail('agent-1@hubtype.com')
    handOffBuilder.withOnFinishPath('thanks-for-contacting') // or handOffBuilder.withOnFinishPayload('thanks-for-contacting')
    handOffBuilder.withCaseInfo(
      'This is some case information that will be available in the new created case'
    )
    handOffBuilder.withNote(
      'This is a note that will be attached to the case as a reminder'
github hubtype / botonic / packages / botonic-cli / templates / handoff / src / actions / transfer-agent.js View on Github external
/*
      Uncomment the lines below before deploying the bot to Hubtype
      in order to test the getOpenQueues call for 'Customer Support'.
    */
    // let openQueues = await getOpenQueues(session)
    let agentEmail = ''
    try {
      agentEmail = (await getAvailableAgents(
        session,
        'HUBTYPE_DESK_QUEUE_ID'
      )).filter(agent => agent == 'agent-name@hubtype.com')[0]
    } catch (e) {}

    let isHandOff = false
    // if (openQueues.queues.indexOf('Customer Support') !== -1) {
    let handOffBuilder = new HandOffBuilder(session)
    handOffBuilder.withQueue('HUBTYPE_DESK_QUEUE_ID')
    handOffBuilder.withAgentEmail('agent-1@hubtype.com')
    handOffBuilder.withOnFinishPath('thanks-for-contacting') // or handOffBuilder.withOnFinishPayload('thanks-for-contacting')
    handOffBuilder.withCaseInfo(
      'This is some case information that will be available in the new created case'
    )
    handOffBuilder.withNote(
      'This is a note that will be attached to the case as a reminder'
    )
    await handOffBuilder.handOff()

    isHandOff = true
    // }
    return { isHandOff }
  }
github hubtype / botonic / packages / botonic-cli / src / commands / run.ts View on Github external
async run() {
    track('Run Botonic CLI')
    const { args, flags } = this.parse(Run)
    const path = flags.path ? resolve(flags.path) : process.cwd()

    //Build project
    await this.botonicApiService.buildIfChanged()
    this.botonicApiService.beforeExit()

    this.botonic = new Botonic(path)
    console.log(this.helpText)
    this.chat_loop()
  }
github hubtype / botonic / packages / botonic-react / src / webview.jsx View on Github external
async close(options) {
        let payload = options ? options.payload : null
        if (options.path) payload = `__PATH_PAYLOAD__${options.path}`
        if (payload) {
            if (options.params) {
                payload = `${payload}?${params2queryString(options.params)}`
            }
            let s = this.state.session
            try {
                let base_url = s._hubtype_api || 'https://api.hubtype.com'
                let resp = await axios({
                    method: 'post',
                    url: `${base_url}/v1/bots/${s.bot.id}/send_postback/`,
                    data: { payload: payload, chat_id: s.user.id }
                })
            } catch (e) {
                console.log(e)
            }
        }
        if (this.state.session.user.provider === 'whatsappnew') {
            location.href = 'https://wa.me/' + this.state.session.user.imp_id;
        }
github hubtype / botonic / packages / botonic-cli / src / commands / webview.ts View on Github external
async run() {
    const { args, flags } = this.parse(Run)

    const path = flags.path ? resolve(flags.path) : process.cwd()
    const context = flags.context ? flags.context : ''

    this.botonic = new Botonic(path)

    this.botonic
      .getWebview(args.webview_page, context)
      .then((response: string) => {
        console.log(response)
      })
  }
}
github hubtype / botonic / packages / botonic-cli / src / commands / input.ts View on Github external
async run() {
    const { args, flags } = this.parse(Run)

    const path = flags.path ? resolve(flags.path) : process.cwd()
    const route = flags.route ? flags.route : ''
    const context = flags.context ? flags.context : ''

    this.botonic = new Botonic(path)

    this.botonic
      .processInput(args.input, route, context)
      .then((response: string) => {
        console.log(response)
      })
      .catch(err => {
        console.log('Error:', err)
      })
  }
}
github hubtype / botonic / packages / botonic-react / src / webchat / webchat.jsx View on Github external
const closeWebview = options => {
    updateWebview()
    if (userInputEnabled) {
      textArea.current.focus()
    }
    if (options && options.payload) {
      sendPayload(options.payload)
    } else if (options && options.path) {
      let params = ''
      if (options.params) params = params2queryString(options.params)
      sendPayload(`__PATH_PAYLOAD__${options.path}?${params}`)
    }
  }
github hubtype / botonic / packages / botonic-react / src / webchat.jsx View on Github external
closeWebview(options) {
        this.setState({ ...this.state, webview: null })
        this.textarea.focus()
        if (options && options.payload) {
            this.sendPayload(options.payload)
        } else if (options && options.path) {
            let params = ''
            if (options.params) params = params2queryString(options.params)
            this.sendPayload(`__PATH_PAYLOAD__${options.path}?${params}`)
        }
    }
github hubtype / botonic / packages / botonic-react / src / components / button.jsx View on Github external
const renderNode = () => {
    if (props.webview) {
      let Webview = props.webview
      let params = ''
      if (props.params) params = params2queryString(props.params)
      return (
        <button>
          {props.children}
        </button>
      )
    } else if (props.path) {
      let payload = `__PATH_PAYLOAD__${props.path}`
      return <button>{props.children}</button>
    } else if (props.payload) {
      return <button>{props.children}</button>
    } else if (props.url) {
      return <button>{props.children}</button>
    }
  }
github hubtype / botonic / packages / botonic-react / src / webchat-app.jsx View on Github external
onStateChange({ user, messagesJSON }) {
    if (!this.hubtypeService && user) {
      let lastMessage = messagesJSON[messagesJSON.length - 1]
      this.hubtypeService = new HubtypeService({
        appId: this.appId,
        user,
        lastMessageId: lastMessage && lastMessage.id,
        onEvent: event => this.onServiceEvent(event),
      })
    }
  }