跳转到主要内容

WhatsApp 客服机器人

要设置您的客服机器人,请转到 WhatsApp → Bots 菜单,并使用 New ChatBot 按钮注册一个新的客服机器人。

您可以通过两种不同的方式更改机器人的功能:通过 JSON可视化编辑器。在编辑器中所做的更改将反映在 JSON 中,反之亦然。

主题和问题

机器人的基本结构按 主题问题 组织。每个主题可以包含多个问题。

可编程性 (Helper)

机器人的各个方面都可以编程以更好地适应您的公司。您可以直接在代码编辑器中访问所有机器人功能:

helper 类中的可用方法:

void ClearAsked()

清除问题和答案历史记录。

void ClearVars()

清除设置的变量。

void CloseTicket(String TextMessage)

结束对话。

void Debug(String debugLine)

添加调试日志。

void DebugVars()

将变量添加到调试日志。

String Deserialize(String json)

将 JSON 字符串反序列化为对象。
返回: Object

void DisableBot()

禁用机器人。

void EnableBot()

启用机器人。

void DisableTopic(String TopicName)

为机器人禁用主题。

void EnableTopic(String TopicName)

为机器人启用主题。

void EnviaPerguntaPorId(String idPergunta)

通过给定的 ID 向客户端发送问题。

String GetVar(String varName)

检索变量的值。
返回: String with the variable value.

void GoSub(String idPergunta)

转到指定的子程序。

String HttpPost(String url, String Header, String Body, String ContentType)

执行 HTTP POST。
返回: String with the returned content after the post.

Boolean isNullOrEmpty(String value)

检查值是否为 null 或空。
返回: true|false

Boolean isValidCnpj(String CNPJ)

检查提供的 CNPJ 是否有效。
返回: true|false

Boolean isValidCpf(String Cpf)

检查提供的 CPF 是否有效。
返回: true|false

Boolean isValidEmail(String email)

检查提供的电子邮件是否有效。
返回: true|false

Boolean isValidNome(String Name)

检查提供的姓名是否有效。
返回: true|false

void LastAskedPop()

删除最后收到的答案。

String LoadFromFile(String FileName)

加载文件的内容。
返回: String with the file content.

String LoadUrl(String url)

从外部 URL 加载内容。
返回: String with the content.

void ParseBadWordsFromText(String fileContent)

添加到脏话列表。

void ParseVariablesFromJSON(String fileContent)

根据提供的 JSON 设置环境变量。

void ParseVariablesFromText(String fileContent)

根据提供的文本设置环境变量。

String SaveVariablesToJSON()

返回包含变量及其相应值的 JSON。

String Serialize(Object obj)

将对象序列化为 JSON 字符串。

Boolean RegularExpressionMatch(String regularExpression, String value)

检查值是否匹配提供的正则表达式。
返回: true|false

String RegularExpressionValue(String regularExpression, String value, Int32 captureGroup)

检查值是否匹配提供的正则表达式。
返回: String with the value of the specified group.

void SendMessageTemplate(String TemplateIdOrName)

从预注册的模板发送消息。

void SendMessageText(String TextMessage)

发送文本消息。

void SetPerguntaAtiva(String idPergunta)

将问题设置为活跃状态。

void SetTag(String newTag)

为联系人添加标签。

void SetVar(String varName, String|Object varValue)

设置变量。

void Sleep(int miliSeconds)

暂停处理。

void StartTyping()

向客户端发送"正在输入"状态。

void TransferTicket(String DestinationLogin)

将工单转移给客服代表。

void UpdateProfileStatus(String newStatus)

更新档案状态。

动态变量

将根据当前联系人进行替换的变量。

变量示例备注
$perfilname$José Maria dos Santos如果不可用,则替换为电话号码。
$perfil-pushname$José Maria如果不可用,则替换为电话号码。
$jid$5511998765432@s.whatsapp.net
$id_atendimento$219482
$id_profile$30129292
$robo_ativo$True/False
$pushname$Support CenterWhatsApp 显示名称
$ou(value1|value2)$value 1在值之间随机交替

机器人示例

复制下面预配置机器人的示例以了解工具的基本操作:

{
"Topicos": [
{
"Id": "1",
"Name": "Commands",
"CondicaoInicio": "",
"CondicaoTermino": "",
"CondicaoInicioResultado": true,
"CondicaoTerminoResultado": false,
"Enabled": true,
"PerguntasPassivas": [
{
"Perguntas": [
{
"IdFrase": 0,
"ListOfDependencies": [],
"DependencyCount": 0,
"Texto": "/FIRST_TIME_USER",
"OnAswerScript": "",
"OnEvaluateScript": ""
}
],
"RespostaPossiveis": [],
"Respostas": [],
"respostaIndex": 0,
"OnAnswerScript": "Boolean OnExecute(SalesBot.LambaHelper helper)\n{\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n\n // your code\n helper.EnviaPerguntaPorId(\"QUAL_NOME\");\n \n retorno = true;\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnExecute - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n}",
"MaxCount": 0,
"UsedCount": 0,
"Id": "FIRST_TIME_USER",
"CanEvaluate": true
}
],
"PerguntasAtivas": [],
"OnAnswerScript": "",
"OnStartScript": "",
"OnEndScript": "",
"CanEvaluate": true
},
{
"Id": "3",
"Name": "Data Topic",
"CondicaoInicio": "",
"CondicaoTermino": "",
"CondicaoInicioResultado": true,
"CondicaoTerminoResultado": false,
"Enabled": true,
"PerguntasPassivas": [
{
"Perguntas": [],
"RespostaPossiveis": [
{
"Resposta": "RIGHT",
"OnAnswerScript": "\nBoolean OnExecute(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n\n // your code\n String name = \"$0$\";\n helper.SetVar(\"NAME\",name);\n helper.ClearAsked();\n helper.EnviaPerguntaPorId(\"QUAL_CPF\");\n retorno = true;\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnExecute - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"OnValidationScript": "\n Boolean OnEvaluate(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnEvaluate - $NameContext$ - $NameObjext$\");\n\n // your code\n retorno = helper.isValidNome(\"$0$\");\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnEvaluate - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"Default": false,
"ClearLast": true,
"RespostaRegEx": null,
"VariavelNome": null,
"VariavelValor": null
},
{
"Resposta": "WRONG",
"OnAnswerScript": "\nBoolean OnExecute(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n\n // your code\n helper.StartTyping();\n helper.Sleep(3000);\n helper.SendMessageText(\"Sorry, I didn't understand... Could you please type your FULL name again?\");\n helper.Sleep(3000);\n helper.EnviaPerguntaPorId(\"QUAL_NOME\");\n\n retorno = true;\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnExecute - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"OnValidationScript": "\n Boolean OnEvaluate(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnEvaluate - $NameContext$ - $NameObjext$\");\n\n // your code\n retorno = !helper.isValidNome(\"$0$\");\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnEvaluate - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"Default": true,
"ClearLast": false,
"RespostaRegEx": null,
"VariavelNome": null,
"VariavelValor": null
}
],
"Respostas": [],
"respostaIndex": 0,
"OnAnswerScript": "Boolean OnExecute(SalesBot.LambaHelper helper)\n{\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n\n // your code\n String name = helper.GetVar(\"NAME\");\n \n if(!helper.isValidNome(name))\n {\n helper.StartTyping();\n helper.Sleep(100);\n helper.SendMessageText(\"Hello! Who am I speaking with?\");\n } \n retorno = true;\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnExecute - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n}",
"MaxCount": 0,
"UsedCount": 0,
"Id": "QUAL_NOME",
"CanEvaluate": true
},
{
"Perguntas": [],
"RespostaPossiveis": [
{
"Resposta": "RIGHT",
"OnAnswerScript": "\nBoolean OnExecute(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n\n // your code\n helper.SetVar(\"CPF\", helper.GetVar(\"0\"));\n helper.EnviaPerguntaPorId(\"END\");\n retorno = true;\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnExecute - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"OnValidationScript": "\n Boolean OnEvaluate(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnEvaluate - $NameContext$ - $NameObjext$\");\n\n // your code\n retorno = helper.isValidCpf(\"$0$\");\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnEvaluate - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"Default": false,
"ClearLast": true,
"RespostaRegEx": null,
"VariavelNome": null,
"VariavelValor": null
},
{
"Resposta": "WRONG",
"OnAnswerScript": "\nBoolean OnExecute(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n helper.SendMessageText(\"Invalid CPF. Please enter it again:\");\n // your code\n retorno = true;\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnExecute - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"OnValidationScript": "\n Boolean OnEvaluate(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnEvaluate - $NameContext$ - $NameObjext$\");\n\n // your code\n String CPF = helper.GetVar(\"0\");\n\n retorno = !helper.isValidCpf(CPF);\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnEvaluate - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"Default": true,
"ClearLast": false,
"RespostaRegEx": null,
"VariavelNome": null,
"VariavelValor": null
}
],
"Respostas": [],
"respostaIndex": 0,
"OnAnswerScript": "Boolean OnExecute(SalesBot.LambaHelper helper)\n{\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n\n // your code\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n\n String cpf = helper.GetVar(\"CPF\");\n String name = helper.GetVar(\"NAME\");\n \n if(!helper.isValidCpf(cpf))\n {\n helper.StartTyping();\n helper.Sleep(100);\n helper.SendMessageText(name + \", please enter your <b>CPF</b> to continue:\");\n } \n retorno = true;\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnExecute - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n}",
"MaxCount": 0,
"UsedCount": 0,
"Id": "QUAL_CPF",
"CanEvaluate": true
},
{
"Perguntas": [],
"RespostaPossiveis": [],
"Respostas": [],
"respostaIndex": 0,
"OnAnswerScript": "\nBoolean OnExecute(SalesBot.LambaHelper helper)\n {\n Boolean retorno = false;\n\n try \n {\n helper.Debug(\"Starting OnExecute - $NameContext$ - $NameObjext$\");\n\n helper.SendMessageText(\"Thank you!\\n\\nWe will contact you as soon as possible.\");\n\n // your code\n retorno = true;\n }\n catch(Exception ex)\n {\n helper.Debug(ex);\n }\n finally\n {\n helper.Debug(\"End OnExecute - $NameContext$ - $NameObjext$\");\n }\n \n return retorno;\n }\n",
"MaxCount": 0,
"UsedCount": 0,
"Id": "END",
"CanEvaluate": true
}
],
"PerguntasAtivas": [],
"OnAnswerScript": "",
"OnStartScript": "",
"OnEndScript": "",
"CanEvaluate": true
}
],
"HistoricoConversa": [],
"BadWords": null,
"BadWordTopic": null,
"Enabled": true,
"OnLoadScript": "",
"OnUnLoadScript": "",
"OnInputScript": "",
"OnTimerScript": "",
"OnIdleScript": "",
"OnAnswerScript": "",
"OnBadWordScript": "",
"BadWordTopicName": "",
"IdCount": 0,
"OnUnknowScript": "",
"IdleTimeInSecconds": 60,
"TimerTimeInSecconds": 5
}

创建您的机器人,将上述内容粘贴到 JSON 编辑器中,然后点击页面底部的 Import

保存 您的机器人,然后运行测试。

测试您的机器人

在将机器人投入使用之前,运行所有必要的测试是至关重要的。使用可用的测试工具:

为了在测试环境中模拟用户创建的客服工单,有两个特殊命令:

命令执行顺序功能
/FIRST_TIME_USER3在新对话(新用户)中发送,当在过去 30 天内 没有 消息交换时。
/START_SESSION4在对话开始时发送,当在过去 30 天内 有过 消息交换时。
/FIRST_TIME_USER_FROM_ME1在由系统发起的新对话(过去 30 天内没有消息交换)中发送(由客服代表或其他方式,而不是用户发起)。
/START_SESSION_FROM_ME2在由客服代表或系统发起的对话中发送(不是由用户发起),其中在不到 30 天内有过消息交换。

这两个命令都将执行同名的主题并启动您的脚本。这些命令在生产环境中由系统自动执行

重要提示

记住创建带有 /START_SESSION/FIRST_TIME_USER 条目的问题来处理这些命令并启动机器人客服会话。