创建完成命令
取票后,Slack会为您(专员)和用户之间创建一个专用频道。您将可以在这个频道内与用户自由对话。
对话完成后,专员可以在专用频道中键入完成的指令,即可结束实时聊天。
请在您在2.1中创建的Slack指令树中设置此指令。
您的结果是什么?
示例树结构 - 完成指令
Slack指令示例树结构 - 完成指令
动手试试看
创建一个对话点 - 完成指令
添加一个对话点并命名为「Done Command」。
在以下的部分,您会添加3个执行动作。请按照以下步骤进行操作并按照次序将执行动作放置于前置动作。
添加第一个执行动作并用以下代码将取票状态转为完成:
return new Promise(async (resolve, reject) => {
try {
const group = await this.getGroupByExternalId({
adminExternalId: this.messageEvent.from,
groupId: this.messageEvent.to,
type: this.channel.type,
channelId: this.channel._id,
})
this.member.groupObj = group
let assignments = []
const assignment = await this.getAssignment({
assignmentId: group.assignment
})
assignments = [assignment]
if (assignment.parentAssignment) {
const parentAssignment = await this.getAssignment({
assignmentId: assignment.parentAssignment
})
const allAssignments = await this.getAssignmentsByParentAssignmentId({
assignmentId: assignment.parentAssignment
})
assignments = [...allAssignments, parentAssignment]
}
let promises = []
let name
if (this.member.name) {
name = this.member.name
} else if (this.member.firstName && this.member.lastName) {
name = `${this.member.firstName} ${this.member.lastName}`
} else if (this.member.firstName) {
name = this.member.firstName
}
let doneMessage = "Done"
if (name) {
doneMessage = `Done by ${name}`
}
console.log("assignments", assignments)
assignments.forEach((obj) => {
console.log("obj.targets", obj.targets)
const target = this.lodash.find(obj.targets, { channel: this.channel._id })
console.log("target", JSON.stringify(target, null, 2))
const updateMessages = this.lodash.map(target.broadcastGroups, (broadcastGroup) => {
return this.updateMessage({
messageTs: broadcastGroup.messageTs,
text: this.lodash.get(obj, "relayMessage.slack.text", "Done"),
attachments: JSON.stringify([
{
text: doneMessage,
fallback: doneMessage,
color: "#36a64f"
}
]),
channel: this.channel,
externalChannelId: broadcastGroup.id
})
})
promises = [...promises, ...updateMessages]
})
await Promise.all(promises)
resolve({
member: this.member
})
} catch (e) {
reject(e)
}
})
- 添加第二个前置动作并用以下代码将对话完成的信息发送到入口频道 (您可以在 let response 的 text 自定义文本):
return new Promise(async (resolve, reject) => {
try {
const member = await this.getMember({ memberId: this.member.groupObj.member })
let response = {
type: "TEXT",
text: "Thank you for your enquiry! We will close the conversation now, you are welcome to contact us again anytime. Bye!"
}
await this.sendMessageToInlet({
messageEvent: this.messageEvent,
channel: this.channel,
response,
})
resolve()
} catch (e) {
reject(e)
}
})
- 添加第3个前置动作并用以下代码结束实时聊天:
return this.endLiveChat({
messageEvent: this.messageEvent,
channel: this.channel
})
- 于Advanced > Response Object中添加二个响应并输入以下代码:
第一个响应:
{
"type": "TEXT",
"text": "Your DONE command has successfully sent. Thanks!"
}
第二个响应 (在完成步骤2.4后即会触发):
{
"type": "BUTTON",
"buttons": [
{
"type": "postback",
"payload": "ARCHIVE",
"title": "Archive Now"
}
],
"text": "Do you want to archive this channel now?"
}
添加一个通用对话点 - 完成指令
- 添加一个通用对话点,然后使用 「AND」创建一个具有两个条件的触发点 (有关创建条件的详细信息,请点击此处):
Slack完成指令触发点
第一个条件 - at bot:
new RegExp(`<@${this.channel.info.botId}`).test(this.messageEvent.data.text)
第二个条件 - command done:
new RegExp("done", "i").test(this.messageEvent.data.text)
- 启用重定向并连接到您为完成指令制作的树对话点。
重定向至完成指令树对话点
- 检查是否可以获得成功结果。