Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
/*
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 }
}
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()
}
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;
}
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)
})
}
}
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)
})
}
}
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}`)
}
}
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}`)
}
}
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>
}
}
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),
})
}
}