Skip to content

Instantly share code, notes, and snippets.

@jcabot
Created December 18, 2019 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcabot/c4f7be8dc989a7e87cb46f3df931abaf to your computer and use it in GitHub Desktop.
Save jcabot/c4f7be8dc989a7e87cb46f3df931abaf to your computer and use it in GitHub Desktop.
Excerpt showing how to transfer the control of the communication from a chatbot to a human
on intent Default_Fallback_Intent from ReactPlatform do
val reactChannel = context.get("chat").get("channel") as String
var reactSlackMap = session.get("react-slack-map") as com.google.common.collect.BiMap<String, String>
if(reactSlackMap === null) {
reactSlackMap = com.google.common.collect.HashBiMap.<String, String>create
session.put("react-slack-map", reactSlackMap)
}
val storedSlackTs = reactSlackMap.get(reactChannel)
if(storedSlackTs === null) {
ReactPlatform.Reply("Sorry I didn't get it, I forward your request to the closest human being")
val slackTs = SlackPlatform.PostMessage("[" + context.get("chat").get("username") + "] " + intent.matchedInput, config.get("slack.channel") as String) as String
reactSlackMap.put(reactChannel, slackTs)
SlackPlatform.PostMessage("_Replies in this thread will be forwarded to the user_", config.get("slack.channel") as String, slackTs)
} else {
SlackPlatform.PostMessage("[" + context.get("chat").get("username") + "] " + intent.matchedInput, config.get("slack.channel") as String, storedSlackTs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment