Rocketchat.closechat
unknown
javascript
4 years ago
1.4 kB
18
Indexable
/* You must provid the Botpress App Webhook from Rocketchat */
const rocketWebhook = 'https://localhost:3000/api/apps/public/6a8e6b6c-7a25-47c9-94e8-5af5075981ad/incoming'
const axios = require('axios')
/**
* @title Close a chat session
* @category Channel Rocket.Chat
* @author LigeroSmart https://ligerosmart.com
*/
const callApi = async () => {
// Prepare the message
const message = {
type: 'text',
text: 'Chat encerrado. Fora do horário de expediente.',
// Markdown enables rich content, for example links or bold text. Otherwise, content will be displayed as-is
markdown: true
}
// Send the message to the user (note the array, since you can send multiple payloads in the same reply)
await bp.events.replyToEvent(event, [message])
const RoomIdAndVisitorToken = event.target.split(':')
// Transfer user
const { data } = await axios.post(rocketWebhook, {
sessionId: RoomIdAndVisitorToken[0],
action: 'close-chat'
})
// The first element returned is the most recent release
//const mostRecentRelease = data[0]
//const latestVersion = mostRecentRelease.name
// You could also save the complete response in the session, then use it later
//session.response = data
}
// Actions are async, so make sure to return a promise
return callApi()
Editor is loading...