├── .gitignore ├── Giphy └── CanYouBot │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── xatkit │ └── example │ └── GiphyBot.java ├── GitHubBots └── GithubStargazer │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── xatkit │ └── example │ ├── GithubStargazerBot.java │ └── StarPayloadUtils.java ├── GreetingsBots ├── GreetingsBot-Extended │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── xatkit │ │ └── example │ │ └── GreetingsBotExtended.java └── GreetingsBot │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── xatkit │ └── example │ └── GreetingsBot.java ├── LanguageProcessorsBots ├── EmojiBots │ ├── EmojiSentimentBot │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── xatkit │ │ │ └── example │ │ │ └── EmojiSentimentBot.java │ └── EmojiToTextBot │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── xatkit │ │ └── example │ │ └── EmojiToTextBot.java ├── LanguageDetectorBot │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── xatkit │ │ └── example │ │ └── LanguageDetectorBot.java ├── README.md ├── RemoveStopWordsBot │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── xatkit │ │ └── example │ │ └── RemoveStopWordsBot.java ├── ToxicityDetectorBot │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── xatkit │ │ └── example │ │ └── ToxicityDetectorBot.java └── YesNoAndSentimentBot │ ├── .gitignore │ ├── pom.xml │ └── src │ └── main │ └── java │ └── com │ └── xatkit │ └── example │ └── YesNoAndSentimentBot.java ├── MessengerBotBasic ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── xatkit │ │ └── example │ │ ├── FileManager.java │ │ ├── MessengerBotBasic.java │ │ └── PropertiesManager.java │ └── resources │ ├── log4j2.xml │ └── pic.jpg ├── README.md ├── SimpleQABot ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── xatkit │ └── example │ └── SimpleQABot.java ├── WeatherBot ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── xatkit │ └── example │ └── WeatherBot.java ├── YoutubeBot ├── README.md ├── docs │ └── img │ │ ├── enable_annotation_processing_intellij.png │ │ └── preview.gif ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── xatkit │ └── example │ ├── YoutubeAPI.java │ ├── YoutubeBot.java │ └── utils │ ├── ResponseParser.java │ └── Video.java ├── community ├── README.md ├── SlackTrelloBot │ ├── .classpath │ ├── .project │ ├── META-INF │ │ └── MANIFEST.MF │ ├── README.md │ ├── SlackTrelloBot.properties │ └── src │ │ ├── SlackTrelloBot.execution │ │ └── SlackTrelloBot.intent └── Twitter │ └── CanYouTweet │ ├── .classpath │ ├── .project │ ├── CanYouTweet.properties │ ├── META-INF │ └── MANIFEST.MF │ ├── README.md │ ├── lib │ └── xatkit-twitter-runtime-1.0.1-SNAPSHOT.jar │ └── src │ ├── CanYouTweet.execution │ └── CanYouTweet.intent └── outdated ├── GithubBot ├── .classpath ├── .project ├── GithubBot.properties ├── META-INF │ └── MANIFEST.MF ├── README.md ├── lib │ └── xatkit-github-runtime-2.1.1-SNAPSHOT.jar └── src │ ├── GithubBot.execution │ └── GithubBot.intent ├── README.md └── ReactSlackLiveChat ├── .classpath ├── .project ├── META-INF └── MANIFEST.MF ├── ReactSlackLiveChat.properties ├── build.properties └── src ├── ReactSlackLiveChat.execution └── ReactSlackLiveChat.intent /.gitignore: -------------------------------------------------------------------------------- 1 | # DialogFlow Account Key 2 | **/*key.json 3 | 4 | # Properties file with credentials 5 | **/*-private*.properties 6 | 7 | # Runtime Data 8 | **/data/ 9 | **/public/ 10 | 11 | # Xatkit logs 12 | **/logs 13 | 14 | # Bin scripts 15 | **/bin 16 | **/target 17 | 18 | 19 | # Eclipse's .settings 20 | **/.settings 21 | 22 | # IntelliJ settings 23 | **/.idea 24 | *.iml -------------------------------------------------------------------------------- /Giphy/CanYouBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | giphy-bot-example 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 1.4.9 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.xatkit 33 | core 34 | 5.0.0-SNAPSHOT 35 | 36 | 37 | 38 | com.xatkit 39 | chat-platform 40 | 3.0.1-SNAPSHOT 41 | 42 | 43 | 44 | com.xatkit 45 | react-platform 46 | 4.0.1-SNAPSHOT 47 | 48 | 49 | 50 | com.xatkit 51 | giphy-platform 52 | 3.0.1-SNAPSHOT 53 | 54 | 55 | 56 | 57 | 58 | org.projectlombok 59 | lombok 60 | 61 | 62 | 63 | 64 | 65 | junit 66 | junit 67 | 68 | 69 | 70 | org.assertj 71 | assertj-core 72 | 73 | 74 | 75 | org.mockito 76 | mockito-core 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.projectlombok 88 | lombok 89 | ${lombok.version} 90 | provided 91 | 92 | 93 | 94 | 95 | 96 | junit 97 | junit 98 | ${junit.version} 99 | test 100 | 101 | 102 | 103 | org.assertj 104 | assertj-core 105 | test 106 | ${assertj.version} 107 | 108 | 109 | 110 | org.mockito 111 | mockito-core 112 | ${mockito-version} 113 | test 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | org.apache.maven.plugins 125 | maven-assembly-plugin 126 | ${maven-assembly-plugin.version} 127 | 128 | 129 | package 130 | 131 | single 132 | 133 | 134 | 135 | 136 | 137 | jar-with-dependencies 138 | 139 | 140 | 141 | com.xatkit.example.GiphyBot 142 | 143 | 144 | giphy-bot 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | org.apache.maven.plugins 154 | maven-assembly-plugin 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /GitHubBots/GithubStargazer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | github-stargazer-bot-example 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 1.4.9 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.xatkit 33 | core 34 | 5.0.0-SNAPSHOT 35 | 36 | 37 | 38 | com.xatkit 39 | chat-platform 40 | 3.0.1-SNAPSHOT 41 | 42 | 43 | 44 | com.xatkit 45 | slack-platform 46 | 3.0.1-SNAPSHOT 47 | 48 | 49 | 50 | com.xatkit 51 | github-platform 52 | 3.0.1-SNAPSHOT 53 | 54 | 55 | 56 | 57 | 58 | org.projectlombok 59 | lombok 60 | 61 | 62 | 63 | 64 | 65 | junit 66 | junit 67 | 68 | 69 | 70 | org.assertj 71 | assertj-core 72 | 73 | 74 | 75 | org.mockito 76 | mockito-core 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.projectlombok 88 | lombok 89 | ${lombok.version} 90 | provided 91 | 92 | 93 | 94 | 95 | 96 | junit 97 | junit 98 | ${junit.version} 99 | test 100 | 101 | 102 | 103 | org.assertj 104 | assertj-core 105 | test 106 | ${assertj.version} 107 | 108 | 109 | 110 | org.mockito 111 | mockito-core 112 | ${mockito-version} 113 | test 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | org.apache.maven.plugins 125 | maven-assembly-plugin 126 | ${maven-assembly-plugin.version} 127 | 128 | 129 | package 130 | 131 | single 132 | 133 | 134 | 135 | 136 | 137 | jar-with-dependencies 138 | 139 | 140 | 141 | com.xatkit.example.GithubStargazerBot 142 | 143 | 144 | github-stargazer-bot 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | org.apache.maven.plugins 154 | maven-assembly-plugin 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /GitHubBots/GithubStargazer/src/main/java/com/xatkit/example/GithubStargazerBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.xatkit.core.XatkitBot; 5 | import com.xatkit.plugins.github.platform.GithubPlatform; 6 | import com.xatkit.plugins.github.platform.io.GithubWebhookEventProvider; 7 | import com.xatkit.plugins.slack.platform.SlackPlatform; 8 | import lombok.val; 9 | import org.apache.commons.configuration2.BaseConfiguration; 10 | import org.apache.commons.configuration2.Configuration; 11 | 12 | import java.text.MessageFormat; 13 | 14 | import static com.xatkit.dsl.DSL.eventIs; 15 | import static com.xatkit.dsl.DSL.fallbackState; 16 | import static com.xatkit.dsl.DSL.model; 17 | import static com.xatkit.dsl.DSL.state; 18 | import static com.xatkit.example.StarPayloadUtils.getRepositoryName; 19 | import static com.xatkit.example.StarPayloadUtils.getRepositoryUrl; 20 | import static com.xatkit.example.StarPayloadUtils.getSenderLogin; 21 | import static com.xatkit.example.StarPayloadUtils.getSenderUrl; 22 | import static com.xatkit.example.StarPayloadUtils.getStargazersCount; 23 | 24 | public class GithubStargazerBot { 25 | 26 | /* 27 | * Your bot is a plain Java application: you need to define a main method to make the created jar executable. 28 | */ 29 | public static void main(String[] args) { 30 | 31 | /* 32 | * Instantiate the platforms we will use in the bot definition. 33 | */ 34 | SlackPlatform slackPlatform = new SlackPlatform(); 35 | GithubPlatform githubPlatform = new GithubPlatform(); 36 | /* 37 | * Similarly, instantiate the intent/event providers we want to use. 38 | */ 39 | GithubWebhookEventProvider githubProvider = new GithubWebhookEventProvider(githubPlatform); 40 | 41 | /* 42 | * Create the states we want to use in our bot. 43 | */ 44 | val init = state("Init"); 45 | val handleNewStar = state("HandleNewStar"); 46 | val handleDeletedStar = state("HandleDeletedStar"); 47 | 48 | /* 49 | * Specify the content of the bot states (i.e. the behavior of the bot). 50 | */ 51 | init 52 | .next() 53 | /* 54 | * We check that the received event matches the ClientReady event defined in the 55 | * ReactEventProvider. The list of events defined in a provider is available in the provider's 56 | * wiki page. 57 | */ 58 | .when(eventIs(GithubWebhookEventProvider.StarCreated)).moveTo(handleNewStar) 59 | .when(eventIs(GithubWebhookEventProvider.StarDeleted)).moveTo(handleDeletedStar); 60 | 61 | 62 | handleNewStar 63 | .body(context -> { 64 | JsonElement githubPayload = ((JsonElement) context.getEventInstance().getValue("json")); 65 | String repositoryUrl = getRepositoryUrl(githubPayload); 66 | String repositoryName = getRepositoryName(githubPayload); 67 | String senderUrl = getSenderUrl(githubPayload); 68 | String senderLogin = getSenderLogin(githubPayload); 69 | int count = getStargazersCount(githubPayload); 70 | slackPlatform.postMessage(context, MessageFormat.format(":tada: New star on <{0} | {1}> by <{2} |" + 71 | " {3}> :confetti_ball:\nCurrent stargazer count: {4} :clap::champagne:", 72 | repositoryUrl, repositoryName, senderUrl, senderLogin, count), 73 | (String) context.getConfiguration().get("slack.channel"), 74 | (String) context.getConfiguration().get("slack.team")); 75 | }) 76 | .next() 77 | .moveTo(init); 78 | 79 | handleDeletedStar 80 | .body(context -> { 81 | JsonElement githubPayload = ((JsonElement) context.getEventInstance().getValue("json")); 82 | String repositoryUrl = getRepositoryUrl(githubPayload); 83 | String repositoryName = getRepositoryName(githubPayload); 84 | String senderUrl = getSenderUrl(githubPayload); 85 | String senderLogin = getSenderLogin(githubPayload); 86 | int count = getStargazersCount(githubPayload); 87 | slackPlatform.postMessage(context, 88 | MessageFormat.format(":sob: <{0} | {1}> unstarred <{2} | {3}> :face_with_head_bandage: " + 89 | "let''s forget about it and build awesome features! " + 90 | ":kissing_heart:\nCurrent stargazer count: {4} :stars:", senderUrl, 91 | senderLogin, repositoryUrl, repositoryName, count), 92 | (String) context.getConfiguration().get("slack.channel"), 93 | (String) context.getConfiguration().get("slack.team")); 94 | }) 95 | .next() 96 | .moveTo(init); 97 | 98 | 99 | /* 100 | * The state that is executed if the engine doesn't find any navigable transition in a state and the state 101 | * doesn't contain a fallback. 102 | */ 103 | val defaultFallback = fallbackState(); 104 | 105 | /* 106 | * Creates the bot model that will be executed by the Xatkit engine. 107 | *

108 | * A bot model contains: 109 | * - A list of intents/events (or libraries) used by the bot. This allows to register the events/intents to 110 | * the NLP 111 | * service. 112 | * - A list of platforms used by the bot. Xatkit will take care of starting and initializing the platforms 113 | * when starting the bot. 114 | * - A list of providers the bot should listen to for events/intents. As for the platforms Xatkit will take 115 | * care of initializing the provider when starting the bot. 116 | * - The list of states the compose the bot (this list can contain the init/fallback state, but it is optional) 117 | * - The entry point of the bot (a.k.a init state) 118 | * - The default fallback state: the state that is executed if the engine doesn't find any navigable 119 | * transition in a state and the state doesn't contain a fallback. 120 | */ 121 | val botModel = model() 122 | .usePlatform(slackPlatform) 123 | .usePlatform(githubPlatform) 124 | .listenTo(githubProvider) 125 | .initState(init) 126 | .defaultFallbackState(defaultFallback); 127 | 128 | Configuration botConfiguration = new BaseConfiguration(); 129 | /* 130 | * Slack platform configuration. 131 | */ 132 | botConfiguration.addProperty("xatkit.slack.token", ""); 133 | botConfiguration.addProperty("slack.channel", ""); 134 | botConfiguration.addProperty("slack.team", ""); 135 | 136 | /* 137 | * Github platform configuration. 138 | */ 139 | botConfiguration.addProperty("xatkit.github.oauth.token", ""); 140 | 141 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 142 | xatkitBot.run(); 143 | /* 144 | * The bot is now started, you can check http://localhost:5000/admin to test it. 145 | * The logs of the bot are stored in the logs folder at the root of this project. 146 | */ 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /GitHubBots/GithubStargazer/src/main/java/com/xatkit/example/StarPayloadUtils.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.google.gson.JsonElement; 4 | 5 | /* 6 | * Utility methods to manipulate Star payloads. 7 | */ 8 | public class StarPayloadUtils { 9 | 10 | public static String getRepositoryUrl(JsonElement payload) { 11 | return payload.getAsJsonObject().getAsJsonObject("repository").get("html_url").getAsString(); 12 | } 13 | 14 | public static String getRepositoryName(JsonElement payload) { 15 | return payload.getAsJsonObject().getAsJsonObject("repository").get("name").getAsString(); 16 | } 17 | 18 | public static String getSenderUrl(JsonElement payload) { 19 | return payload.getAsJsonObject().getAsJsonObject("sender").get("html_url").getAsString(); 20 | } 21 | 22 | public static String getSenderLogin(JsonElement payload) { 23 | return payload.getAsJsonObject().getAsJsonObject("sender").get("login").getAsString(); 24 | } 25 | 26 | public static int getStargazersCount(JsonElement payload) { 27 | return payload.getAsJsonObject().getAsJsonObject("repository").get("stargazers_count").getAsInt(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /GreetingsBots/GreetingsBot-Extended/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | greetings-bot-extended-example 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 1.4.9 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.xatkit 33 | core 34 | 5.0.0-SNAPSHOT 35 | 36 | 37 | 38 | com.xatkit 39 | chat-platform 40 | 3.0.1-SNAPSHOT 41 | 42 | 43 | 44 | com.xatkit 45 | react-platform 46 | 4.0.1-SNAPSHOT 47 | 48 | 49 | 50 | 51 | 52 | org.projectlombok 53 | lombok 54 | 55 | 56 | 57 | 58 | 59 | junit 60 | junit 61 | 62 | 63 | 64 | org.assertj 65 | assertj-core 66 | 67 | 68 | 69 | org.mockito 70 | mockito-core 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.projectlombok 82 | lombok 83 | ${lombok.version} 84 | provided 85 | 86 | 87 | 88 | 89 | 90 | junit 91 | junit 92 | ${junit.version} 93 | test 94 | 95 | 96 | 97 | org.assertj 98 | assertj-core 99 | test 100 | ${assertj.version} 101 | 102 | 103 | 104 | org.mockito 105 | mockito-core 106 | ${mockito-version} 107 | test 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.apache.maven.plugins 119 | maven-assembly-plugin 120 | ${maven-assembly-plugin.version} 121 | 122 | 123 | package 124 | 125 | single 126 | 127 | 128 | 129 | 130 | 131 | jar-with-dependencies 132 | 133 | 134 | 135 | com.xatkit.example.GreetingsBotExtended 136 | 137 | 138 | greetings-bot-extended 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | org.apache.maven.plugins 148 | maven-assembly-plugin 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /GreetingsBots/GreetingsBot-Extended/src/main/java/com/xatkit/example/GreetingsBotExtended.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.core.XatkitBot; 4 | import com.xatkit.plugins.react.platform.ReactPlatform; 5 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 6 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 7 | import lombok.val; 8 | import org.apache.commons.configuration2.BaseConfiguration; 9 | import org.apache.commons.configuration2.Configuration; 10 | 11 | import static com.xatkit.dsl.DSL.eventIs; 12 | import static com.xatkit.dsl.DSL.fallbackState; 13 | import static com.xatkit.dsl.DSL.intent; 14 | import static com.xatkit.dsl.DSL.intentIs; 15 | import static com.xatkit.dsl.DSL.model; 16 | import static com.xatkit.dsl.DSL.state; 17 | 18 | public class GreetingsBotExtended { 19 | 20 | /* 21 | * Your bot is a plain Java application: you need to define a main method to make the created jar executable. 22 | */ 23 | public static void main(String[] args) { 24 | 25 | /* 26 | * Define the intents our bot will react to. 27 | */ 28 | val greetings = intent("Greetings") 29 | .trainingSentence("Hi") 30 | .trainingSentence("Hello") 31 | .trainingSentence("Good morning") 32 | .trainingSentence("Good afternoon"); 33 | 34 | val howAreYou = intent("HowAreYou") 35 | .trainingSentence("How are you?") 36 | .trainingSentence("What's up?") 37 | .trainingSentence("How do you feel?"); 38 | 39 | val fine = intent("Fine") 40 | .trainingSentence("I am fine") 41 | .trainingSentence("Fine") 42 | .trainingSentence("fine"); 43 | 44 | val sad = intent("Sad") 45 | .trainingSentence("Not so good") 46 | .trainingSentence("I am sad") 47 | .trainingSentence("Sad"); 48 | 49 | /* 50 | * Instantiate the platform we will use in the bot definition. 51 | */ 52 | /* 53 | * Similarly, instantiate the intent/event providers we want to use. 54 | */ 55 | ReactPlatform reactPlatform = new ReactPlatform(); 56 | ReactEventProvider reactEventProvider = reactPlatform.getReactEventProvider(); 57 | ReactIntentProvider reactIntentProvider = reactPlatform.getReactIntentProvider(); 58 | 59 | /* 60 | * Create the states we want to use in our bot. 61 | */ 62 | val init = state("Init"); 63 | val awaitingInput = state("AwaitingInput"); 64 | val handleWelcome = state("HandleWelcome"); 65 | val handleWhatsUp = state("HandleWhatsUp"); 66 | val handleFine = state("HandleFine"); 67 | val handleSad = state("HandleSad"); 68 | 69 | /* 70 | * Specify the content of the bot states (i.e. the behavior of the bot). 71 | */ 72 | init 73 | .next() 74 | /* 75 | * We check that the received event matches the ClientReady event defined in the 76 | * ReactEventProvider. The list of events defined in a provider is available in the provider's 77 | * wiki page. 78 | */ 79 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(awaitingInput); 80 | 81 | awaitingInput 82 | .next() 83 | /* 84 | * The Xatkit DSL offers dedicated predicates (intentIs(IntentDefinition) and eventIs 85 | * (EventDefinition) to check received intents/events. 86 | *

87 | * You can also check a condition over the underlying bot state using the following syntax: 88 | *

 89 |                  * {@code
 90 |                  * .when(context -> [condition manipulating the context]).moveTo(state);
 91 |                  * }
 92 |                  * 
93 | */ 94 | .when(intentIs(greetings)).moveTo(handleWelcome) 95 | .when(intentIs(howAreYou)).moveTo(handleWhatsUp); 96 | 97 | handleWelcome 98 | .body(context -> reactPlatform.reply(context, "Hi, nice to meet you!")) 99 | .next() 100 | /* 101 | * A transition that is automatically navigated: in this case once we have answered the user we 102 | * want to go back in a state where we wait for the next intent. 103 | */ 104 | .moveTo(awaitingInput); 105 | 106 | handleWhatsUp 107 | .body(context -> reactPlatform.reply(context, "I am fine and you?")) 108 | .next() 109 | .when(intentIs(fine)).moveTo(handleFine) 110 | .when(intentIs(sad)).moveTo(handleSad); 111 | 112 | handleFine 113 | .body(context -> reactPlatform.reply(context, "Great!")) 114 | .next() 115 | .moveTo(awaitingInput); 116 | 117 | handleSad 118 | .body(context -> reactPlatform.reply(context, "Oh, let me know if I can do something for you :/")) 119 | .next() 120 | .moveTo(awaitingInput); 121 | 122 | /* 123 | * The state that is executed if the engine doesn't find any navigable transition in a state and the state 124 | * doesn't contain a fallback. 125 | */ 126 | val defaultFallback = fallbackState() 127 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't, get it")); 128 | 129 | /* 130 | * Creates the bot model that will be executed by the Xatkit engine. 131 | *

132 | * A bot model contains: 133 | * - A list of platforms used by the bot. Xatkit will take care of starting and initializing the platforms 134 | * when starting the bot. 135 | * - A list of providers the bot should listen to for events/intents. As for the platforms Xatkit will take 136 | * care of initializing the provider when starting the bot. 137 | * - The entry point of the bot (a.k.a init state). Full list of intents and states are calculated based on this entry point 138 | * - The default fallback state: the state that is executed if the engine doesn't find any navigable 139 | * transition in a state and the state doesn't contain a fallback. 140 | */ 141 | val botModel = model() 142 | .usePlatform(reactPlatform) 143 | .listenTo(reactEventProvider) 144 | .listenTo(reactIntentProvider) 145 | .initState(init) 146 | .defaultFallbackState(defaultFallback); 147 | 148 | Configuration botConfiguration = new BaseConfiguration(); 149 | /* 150 | * Add configuration properties (e.g. authentication tokens, platform tuning, intent provider to use). 151 | * Check the corresponding platform's wiki page for further information on optional/mandatory parameters and 152 | * their values. 153 | */ 154 | 155 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 156 | xatkitBot.run(); 157 | /* 158 | * The bot is now started, you can check http://localhost:5000/admin to test it. 159 | * The logs of the bot are stored in the logs folder at the root of this project. 160 | */ 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /GreetingsBots/GreetingsBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | greetings-bot-example 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 1.4.9 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.xatkit 33 | core 34 | 5.0.0-SNAPSHOT 35 | 36 | 37 | 38 | com.xatkit 39 | chat-platform 40 | 3.0.1-SNAPSHOT 41 | 42 | 43 | 44 | com.xatkit 45 | react-platform 46 | 4.0.1-SNAPSHOT 47 | 48 | 49 | 50 | 51 | 52 | org.projectlombok 53 | lombok 54 | 55 | 56 | 57 | 58 | 59 | junit 60 | junit 61 | 62 | 63 | 64 | org.assertj 65 | assertj-core 66 | 67 | 68 | 69 | org.mockito 70 | mockito-core 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.projectlombok 82 | lombok 83 | ${lombok.version} 84 | provided 85 | 86 | 87 | 88 | 89 | 90 | junit 91 | junit 92 | ${junit.version} 93 | test 94 | 95 | 96 | 97 | org.assertj 98 | assertj-core 99 | test 100 | ${assertj.version} 101 | 102 | 103 | 104 | org.mockito 105 | mockito-core 106 | ${mockito-version} 107 | test 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.apache.maven.plugins 119 | maven-assembly-plugin 120 | ${maven-assembly-plugin.version} 121 | 122 | 123 | package 124 | 125 | single 126 | 127 | 128 | 129 | 130 | 131 | jar-with-dependencies 132 | 133 | 134 | 135 | com.xatkit.example.GreetingsBot 136 | 137 | 138 | greetings-bot 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | org.apache.maven.plugins 148 | maven-assembly-plugin 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/EmojiBots/EmojiSentimentBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | emoji-sentiment-bot 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | com.xatkit 32 | core 33 | 5.0.0-SNAPSHOT 34 | 35 | 36 | 37 | com.xatkit 38 | chat-platform 39 | 3.0.1-SNAPSHOT 40 | 41 | 42 | 43 | com.xatkit 44 | react-platform 45 | 4.0.1-SNAPSHOT 46 | 47 | 48 | 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | 54 | 55 | 56 | 57 | 58 | junit 59 | junit 60 | 61 | 62 | 63 | org.assertj 64 | assertj-core 65 | 66 | 67 | 68 | org.mockito 69 | mockito-core 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | org.projectlombok 81 | lombok 82 | ${lombok.version} 83 | provided 84 | 85 | 86 | 87 | 88 | 89 | junit 90 | junit 91 | ${junit.version} 92 | test 93 | 94 | 95 | 96 | org.assertj 97 | assertj-core 98 | test 99 | ${assertj.version} 100 | 101 | 102 | 103 | org.mockito 104 | mockito-core 105 | ${mockito-version} 106 | test 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-assembly-plugin 119 | ${maven-assembly-plugin.version} 120 | 121 | 122 | package 123 | 124 | single 125 | 126 | 127 | 128 | 129 | 130 | jar-with-dependencies 131 | 132 | 133 | 134 | com.xatkit.example.EmojiSentimentBot 135 | 136 | 137 | emoji-sentiment-bot 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | org.apache.maven.plugins 147 | maven-assembly-plugin 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/EmojiBots/EmojiSentimentBot/src/main/java/com/xatkit/example/EmojiSentimentBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.core.XatkitBot; 4 | 5 | import com.xatkit.core.recognition.processor.EmojiData; 6 | import com.xatkit.core.recognition.processor.EmojiPostProcessor; 7 | import com.xatkit.plugins.react.platform.ReactPlatform; 8 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 9 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 10 | import lombok.val; 11 | import org.apache.commons.configuration2.BaseConfiguration; 12 | import org.apache.commons.configuration2.Configuration; 13 | 14 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.ENABLE_RECOGNITION_ANALYTICS; 15 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.RECOGNITION_POSTPROCESSORS_KEY; 16 | 17 | import java.util.Set; 18 | 19 | import static com.xatkit.dsl.DSL.any; 20 | import static com.xatkit.dsl.DSL.eventIs; 21 | import static com.xatkit.dsl.DSL.fallbackState; 22 | import static com.xatkit.dsl.DSL.intent; 23 | import static com.xatkit.dsl.DSL.intentIs; 24 | import static com.xatkit.dsl.DSL.model; 25 | import static com.xatkit.dsl.DSL.state; 26 | 27 | 28 | /** 29 | * This is an example bot which uses EmojiPostProcessor, designed with Xatkit. 30 | *

31 | * You can check our wiki 32 | * to learn more about bot creation, supported platforms, and advanced usage. 33 | */ 34 | public class EmojiSentimentBot { 35 | 36 | 37 | public static void main(String[] args) { 38 | 39 | val Emojis = intent("Emojis") 40 | .trainingSentence("EMOJIS") 41 | .parameter("emojis").fromFragment("EMOJIS").entity(any()); 42 | 43 | ReactPlatform reactPlatform = new ReactPlatform(); 44 | ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform); 45 | ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform); 46 | 47 | val init = state("Init"); 48 | val handleEmojis = state("HandleEmojis"); 49 | val handleWelcome = state("HandleWelcome"); 50 | 51 | init 52 | .next() 53 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(handleWelcome); 54 | 55 | handleWelcome 56 | .body(context -> { 57 | reactPlatform.reply(context, "Hi \uD83D\uDC4B I am a sentiment analyzer bot"); 58 | reactPlatform.reply(context, "Feel free to write some emojis and I'll guess your mood!"); 59 | }) 60 | .next() 61 | .moveTo(handleEmojis); 62 | 63 | handleEmojis 64 | .body(context -> { 65 | Set emojis = (Set) context.getIntent().getNlpData() 66 | .get("nlp.emoji.emojiDataSet"); 67 | String message = "Sorry, couldn't read any emoji..."; 68 | if (!emojis.isEmpty()) { 69 | 70 | double sentiment = 0; 71 | for (EmojiData e : emojis) { 72 | double positiveSentiment = e.getPositiveSentiment() * e.getOccurrences(); 73 | sentiment += positiveSentiment; 74 | double negativeSentiment = e.getNegativeSentiment() * e.getOccurrences(); 75 | sentiment -= negativeSentiment; 76 | } 77 | /* 78 | * sentiment is now in [-1,1]. -1 represents negative sentiment, while 1 represents positive 79 | * sentiment. 80 | * Note that this metric is probably too simple: it is used in this example to showcase what 81 | * can be done with the sentiment analysis processor for emojis, but it should be adapted to 82 | * your specific use case. 83 | */ 84 | reactPlatform.reply(context, String.valueOf(sentiment)); 85 | if (Math.abs(sentiment) < 0.1) { 86 | message = "I think your mood is quite neutral... \uD83D\uDE10"; 87 | } else if (sentiment > 0) { 88 | message = "You seem to be quite happy \uD83D\uDE09"; 89 | } else { 90 | message = "You look sad...\uD83D\uDE15"; 91 | } 92 | } 93 | reactPlatform.reply(context, message); 94 | }) 95 | .next() 96 | .when(intentIs(Emojis)).moveTo(handleEmojis); 97 | 98 | 99 | val defaultFallback = fallbackState() 100 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't get it")); 101 | 102 | val botModel = model() 103 | .usePlatform(reactPlatform) 104 | .listenTo(reactEventProvider) 105 | .listenTo(reactIntentProvider) 106 | .initState(init) 107 | .defaultFallbackState(defaultFallback); 108 | 109 | Configuration botConfiguration = new BaseConfiguration(); 110 | botConfiguration.setProperty(RECOGNITION_POSTPROCESSORS_KEY,"EmojiPostProcessor"); 111 | botConfiguration.setProperty("xatkit.dialogflow.projectId", "YOUR-PROJECT-ID"); 112 | botConfiguration.setProperty("xatkit.dialogflow.credentials.path", "YOUR-CREDENTIALS-PATH"); 113 | botConfiguration.setProperty("xatkit.dialogflow.language", "en-US"); 114 | botConfiguration.setProperty("xatkit.dialogflow.clean_on_startup", true); 115 | botConfiguration.setProperty(ENABLE_RECOGNITION_ANALYTICS, false); 116 | 117 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 118 | xatkitBot.run(); 119 | /* 120 | * The bot is now started, you can check http://localhost:5000/admin to test it. 121 | * The logs of the bot are stored in the logs folder at the root of this project. 122 | */ 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/EmojiBots/EmojiToTextBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | emoji-to-text-bot 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | com.xatkit 32 | core 33 | 5.0.0-SNAPSHOT 34 | 35 | 36 | 37 | com.xatkit 38 | chat-platform 39 | 3.0.1-SNAPSHOT 40 | 41 | 42 | 43 | com.xatkit 44 | react-platform 45 | 4.0.1-SNAPSHOT 46 | 47 | 48 | 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | 54 | 55 | 56 | 57 | 58 | junit 59 | junit 60 | 61 | 62 | 63 | org.assertj 64 | assertj-core 65 | 66 | 67 | 68 | org.mockito 69 | mockito-core 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | org.projectlombok 81 | lombok 82 | ${lombok.version} 83 | provided 84 | 85 | 86 | 87 | 88 | 89 | junit 90 | junit 91 | ${junit.version} 92 | test 93 | 94 | 95 | 96 | org.assertj 97 | assertj-core 98 | test 99 | ${assertj.version} 100 | 101 | 102 | 103 | org.mockito 104 | mockito-core 105 | ${mockito-version} 106 | test 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-assembly-plugin 119 | ${maven-assembly-plugin.version} 120 | 121 | 122 | package 123 | 124 | single 125 | 126 | 127 | 128 | 129 | 130 | jar-with-dependencies 131 | 132 | 133 | 134 | com.xatkit.example.EmojiToTextBot 135 | 136 | 137 | emoji-to-text-bot 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | org.apache.maven.plugins 147 | maven-assembly-plugin 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/EmojiBots/EmojiToTextBot/src/main/java/com/xatkit/example/EmojiToTextBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.core.XatkitBot; 4 | 5 | import com.xatkit.core.recognition.processor.EmojiToTextPreProcessor; 6 | import com.xatkit.plugins.react.platform.ReactPlatform; 7 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 8 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 9 | import lombok.val; 10 | import org.apache.commons.configuration2.BaseConfiguration; 11 | import org.apache.commons.configuration2.Configuration; 12 | 13 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.ENABLE_RECOGNITION_ANALYTICS; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.RECOGNITION_PREPROCESSORS_KEY; 19 | import static com.xatkit.dsl.DSL.any; 20 | import static com.xatkit.dsl.DSL.countryCode; 21 | import static com.xatkit.dsl.DSL.eventIs; 22 | import static com.xatkit.dsl.DSL.fallbackState; 23 | import static com.xatkit.dsl.DSL.intent; 24 | import static com.xatkit.dsl.DSL.intentIs; 25 | import static com.xatkit.dsl.DSL.model; 26 | import static com.xatkit.dsl.DSL.state; 27 | 28 | 29 | /** 30 | * This is an example bot which uses EmojiToTextPreProcessor, designed with Xatkit. 31 | *

32 | * You can check our wiki 33 | * to learn more about bot creation, supported platforms, and advanced usage. 34 | */ 35 | public class EmojiToTextBot { 36 | 37 | 38 | public static void main(String[] args) { 39 | 40 | val IAmFrom = intent("IAmFrom") 41 | .trainingSentence("I am from COUNTRY") 42 | .trainingSentence("From COUNTRY") 43 | .trainingSentence("COUNTRY") 44 | .parameter("country").fromFragment("COUNTRY").entity(countryCode()); 45 | 46 | val FavouriteAnimal = intent("FavouriteAimal") 47 | .trainingSentence("My favorite animal is ANIMAL") 48 | .trainingSentence("It is ANIMAL") 49 | .trainingSentence("It is the ANIMAL") 50 | .trainingSentence("The ANIMAL") 51 | .trainingSentence("ANIMAL") 52 | .parameter("animal").fromFragment("ANIMAL").entity(any()); 53 | 54 | ReactPlatform reactPlatform = new ReactPlatform(); 55 | ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform); 56 | ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform); 57 | 58 | val init = state("Init"); 59 | val handleWelcome = state("HandleWelcome"); 60 | val handleIAmFrom = state("HandleIAmFrom"); 61 | val handleAnimal = state("HandleAnimal"); 62 | 63 | 64 | init 65 | .next() 66 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(handleWelcome); 67 | 68 | handleWelcome 69 | .body(context -> reactPlatform.reply(context, 70 | "Hi! Where are you from?")) 71 | .next() 72 | .when(intentIs(IAmFrom)).moveTo(handleIAmFrom); 73 | 74 | handleIAmFrom 75 | .body(context -> { 76 | Map countryMap = (Map) context.getIntent().getValue("country"); 77 | String country = (String) countryMap.get("name"); 78 | reactPlatform.reply(context, country + "? That's cool!"); 79 | reactPlatform.reply(context, "What is your favorite animal?"); 80 | 81 | }) 82 | .next() 83 | .when(intentIs(FavouriteAnimal)).moveTo(handleAnimal); 84 | 85 | handleAnimal 86 | .body(context -> { 87 | String animal = (String) context.getIntent().getValue("animal"); 88 | reactPlatform.reply(context, animal + "? Good choice \uD83D\uDE0F"); 89 | reactPlatform.reply(context, "Thank you for your collaboration \uD83D\uDE0A"); 90 | }) 91 | .next() 92 | .moveTo(handleWelcome); 93 | 94 | val defaultFallback = fallbackState() 95 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't get it")); 96 | 97 | val botModel = model() 98 | .usePlatform(reactPlatform) 99 | .listenTo(reactEventProvider) 100 | .listenTo(reactIntentProvider) 101 | .initState(init) 102 | .defaultFallbackState(defaultFallback); 103 | 104 | Configuration botConfiguration = new BaseConfiguration(); 105 | botConfiguration.setProperty(RECOGNITION_PREPROCESSORS_KEY, "EmojiToTextPreProcessor"); 106 | botConfiguration.setProperty(EmojiToTextPreProcessor.REMOVE_EMOJIS, false); 107 | botConfiguration.setProperty("xatkit.dialogflow.projectId", "YOUR-PROJECT-ID"); 108 | botConfiguration.setProperty("xatkit.dialogflow.credentials.path", "YOUR-CREDENTIALS-PATH"); 109 | botConfiguration.setProperty("xatkit.dialogflow.language", "en-US"); 110 | botConfiguration.setProperty("xatkit.dialogflow.clean_on_startup", true); 111 | botConfiguration.setProperty(ENABLE_RECOGNITION_ANALYTICS, false); 112 | 113 | 114 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 115 | xatkitBot.run(); 116 | /* 117 | * The bot is now started, you can check http://localhost:5000/admin to test it. 118 | * The logs of the bot are stored in the logs folder at the root of this project. 119 | */ 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/LanguageDetectorBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | language-detector-bot 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | com.xatkit 32 | core 33 | 5.0.0-SNAPSHOT 34 | 35 | 36 | 37 | com.xatkit 38 | chat-platform 39 | 3.0.1-SNAPSHOT 40 | 41 | 42 | 43 | com.xatkit 44 | react-platform 45 | 4.0.1-SNAPSHOT 46 | 47 | 48 | 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | 54 | 55 | 56 | 57 | 58 | junit 59 | junit 60 | 61 | 62 | 63 | org.assertj 64 | assertj-core 65 | 66 | 67 | 68 | org.mockito 69 | mockito-core 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | org.projectlombok 81 | lombok 82 | ${lombok.version} 83 | provided 84 | 85 | 86 | 87 | 88 | 89 | junit 90 | junit 91 | ${junit.version} 92 | test 93 | 94 | 95 | 96 | org.assertj 97 | assertj-core 98 | test 99 | ${assertj.version} 100 | 101 | 102 | 103 | org.mockito 104 | mockito-core 105 | ${mockito-version} 106 | test 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-assembly-plugin 119 | ${maven-assembly-plugin.version} 120 | 121 | 122 | package 123 | 124 | single 125 | 126 | 127 | 128 | 129 | 130 | jar-with-dependencies 131 | 132 | 133 | 134 | com.xatkit.example.LanguageDetectorBot 135 | 136 | 137 | language-detector-bot 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | org.apache.maven.plugins 147 | maven-assembly-plugin 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/LanguageDetectorBot/src/main/java/com/xatkit/example/LanguageDetectorBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.core.XatkitBot; 4 | import com.xatkit.core.recognition.dialogflow.DialogFlowConfiguration; 5 | import com.xatkit.core.recognition.processor.LanguageDetectionPostProcessor; 6 | import com.xatkit.core.recognition.processor.LanguageDetectionScore; 7 | import com.xatkit.plugins.react.platform.ReactPlatform; 8 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 9 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 10 | import lombok.val; 11 | import org.apache.commons.configuration2.BaseConfiguration; 12 | import org.apache.commons.configuration2.Configuration; 13 | 14 | import java.util.List; 15 | 16 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.ENABLE_RECOGNITION_ANALYTICS; 17 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.RECOGNITION_POSTPROCESSORS_KEY; 18 | import static com.xatkit.dsl.DSL.any; 19 | import static com.xatkit.dsl.DSL.eventIs; 20 | import static com.xatkit.dsl.DSL.fallbackState; 21 | import static com.xatkit.dsl.DSL.intent; 22 | import static com.xatkit.dsl.DSL.intentIs; 23 | import static com.xatkit.dsl.DSL.model; 24 | import static com.xatkit.dsl.DSL.state; 25 | import static java.util.Objects.nonNull; 26 | 27 | 28 | /** 29 | * This is an example bot which uses LanguagePredictionPostProcessor, designed with Xatkit. 30 | *

31 | * You can check our wiki 32 | * to learn more about bot creation, supported platforms, and advanced usage. 33 | */ 34 | public class LanguageDetectorBot { 35 | 36 | 37 | public static void main(String[] args) { 38 | 39 | val question = intent("comment") 40 | .trainingSentence("COMMENT") 41 | .parameter("comment").fromFragment("COMMENT").entity(any()); 42 | 43 | ReactPlatform reactPlatform = new ReactPlatform(); 44 | ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform); 45 | ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform); 46 | 47 | val init = state("Init"); 48 | val awaitingInput = state("AwaitingInput"); 49 | val handleWelcome = state("HandleWelcome"); 50 | val handleComment = state("HandleComment"); 51 | 52 | init 53 | .next() 54 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(handleWelcome); 55 | 56 | handleWelcome 57 | .body(context -> reactPlatform.reply(context, 58 | "Hi, I am your favourite bot :) I can guess the language you talk. Just say something!")) 59 | .next() 60 | .moveTo(awaitingInput); 61 | 62 | awaitingInput 63 | .next() 64 | .when(intentIs(question)).moveTo(handleComment); 65 | 66 | handleComment 67 | .body(context -> { 68 | LanguageDetectionScore score1 = (LanguageDetectionScore) 69 | context.getIntent().getNlpData().get("nlp.opennlp.langdetect.lastInput"); 70 | if (nonNull(score1)) { 71 | List languages = score1.getLanguageNames(); 72 | reactPlatform.reply(context, 73 | "I think this message language is '" + languages.get(0) + "'"); 74 | } 75 | LanguageDetectionScore score2 = 76 | (LanguageDetectionScore) context.getSession().get("nlp.opennlp.langdetect.lastNInputs"); 77 | if (nonNull(score2)) { 78 | List languages = score2.getLanguageNames(); 79 | reactPlatform.reply(context, 80 | "And based on the entire conversation, I think you are writing in '" 81 | + languages.get(0) + "' language"); 82 | } 83 | }) 84 | .next() 85 | .moveTo(awaitingInput); 86 | 87 | val defaultFallback = fallbackState() 88 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't get it")); 89 | 90 | val botModel = model() 91 | .usePlatform(reactPlatform) 92 | .listenTo(reactEventProvider) 93 | .listenTo(reactIntentProvider) 94 | .initState(init) 95 | .defaultFallbackState(defaultFallback); 96 | 97 | Configuration botConfiguration = new BaseConfiguration(); 98 | botConfiguration.setProperty(RECOGNITION_POSTPROCESSORS_KEY, "LanguageDetectionPostProcessor"); 99 | botConfiguration.setProperty(LanguageDetectionPostProcessor.MAX_NUM_USER_MESSAGES, 10); 100 | botConfiguration.setProperty(LanguageDetectionPostProcessor.MAX_NUM_LANGUAGES_IN_SCORE, 3); 101 | botConfiguration.setProperty(LanguageDetectionPostProcessor.OPENNLP_MODEL_PATH_PARAMETER_KEY, ""); 104 | botConfiguration.setProperty(DialogFlowConfiguration.GOOGLE_CREDENTIALS_PATH_KEY, " 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | remove-stopwords-bot 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.12 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 3.9.1 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.xatkit 33 | core 34 | 5.0.0-SNAPSHOT 35 | 36 | 37 | 38 | com.xatkit 39 | chat-platform 40 | 3.0.1-SNAPSHOT 41 | 42 | 43 | 44 | com.xatkit 45 | react-platform 46 | 4.0.1-SNAPSHOT 47 | 48 | 49 | 50 | 51 | 52 | org.projectlombok 53 | lombok 54 | 55 | 56 | 57 | 58 | 59 | junit 60 | junit 61 | 62 | 63 | 64 | org.assertj 65 | assertj-core 66 | 67 | 68 | 69 | org.mockito 70 | mockito-core 71 | 72 | 73 | 74 | 75 | 76 | edu.stanford.nlp 77 | stanford-corenlp 78 | 3.9.2 79 | 80 | 81 | com.google.protobuf 82 | protobuf-java 83 | 84 | 85 | 86 | 87 | 88 | edu.stanford.nlp 89 | stanford-corenlp 90 | 3.9.2 91 | models 92 | 93 | 94 | com.google.protobuf 95 | protobuf-java 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | org.projectlombok 109 | lombok 110 | ${lombok.version} 111 | provided 112 | 113 | 114 | 115 | 116 | 117 | junit 118 | junit 119 | ${junit.version} 120 | test 121 | 122 | 123 | 124 | org.assertj 125 | assertj-core 126 | test 127 | ${assertj.version} 128 | 129 | 130 | 131 | org.mockito 132 | mockito-core 133 | ${mockito-version} 134 | test 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | org.apache.maven.plugins 146 | maven-assembly-plugin 147 | ${maven-assembly-plugin.version} 148 | 149 | 150 | package 151 | 152 | single 153 | 154 | 155 | 156 | 157 | 158 | jar-with-dependencies 159 | 160 | 161 | 162 | com.xatkit.example.RemoveStopWordsBot 163 | 164 | 165 | remove-stopwords-bot 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | org.apache.maven.plugins 175 | maven-assembly-plugin 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/RemoveStopWordsBot/src/main/java/com/xatkit/example/RemoveStopWordsBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.core.XatkitBot; 4 | import com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration; 5 | import com.xatkit.plugins.react.platform.ReactPlatform; 6 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 7 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 8 | import lombok.val; 9 | import org.apache.commons.configuration2.BaseConfiguration; 10 | import org.apache.commons.configuration2.Configuration; 11 | 12 | import static com.xatkit.dsl.DSL.any; 13 | import static com.xatkit.dsl.DSL.eventIs; 14 | import static com.xatkit.dsl.DSL.fallbackState; 15 | import static com.xatkit.dsl.DSL.intent; 16 | import static com.xatkit.dsl.DSL.intentIs; 17 | import static com.xatkit.dsl.DSL.model; 18 | import static com.xatkit.dsl.DSL.state; 19 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.*; 20 | 21 | /** 22 | * This is an example bot which uses the RemoveEnglishStopWordsPostProcessor, designed with Xatkit. 23 | *

24 | * You can check our wiki 25 | * to learn more about bot creation, supported platforms, and advanced usage. 26 | */ 27 | public class RemoveStopWordsBot { 28 | 29 | public static void main(String[] args) { 30 | 31 | val list = intent("List") 32 | .trainingSentence("LIST") 33 | .parameter("list").fromFragment("LIST").entity(any()); 34 | 35 | ReactPlatform reactPlatform = new ReactPlatform(); 36 | ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform); 37 | ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform); 38 | 39 | val init = state("Init"); 40 | val awaitingInput = state("AwaitingInput"); 41 | val handleWelcome = state("HandleWelcome"); 42 | val handleList = state("HandleList"); 43 | 44 | init 45 | .next() 46 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(handleWelcome); 47 | 48 | handleWelcome 49 | .body(context -> reactPlatform.reply(context, 50 | "Hi, I am your favourite bot :)")) 51 | .next() 52 | .moveTo(awaitingInput); 53 | 54 | awaitingInput 55 | .next() 56 | .when(intentIs(list)).moveTo(handleList); 57 | 58 | handleList 59 | .body(context -> { 60 | String list_str = (String) context.getIntent().getValue("list"); 61 | String[] items = list_str.split(","); 62 | for (String item : items) { 63 | reactPlatform.reply(context, item); 64 | } 65 | }) 66 | .next() 67 | .moveTo(awaitingInput); 68 | 69 | val defaultFallback = fallbackState() 70 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't get it")); 71 | 72 | val botModel = model() 73 | .usePlatform(reactPlatform) 74 | .listenTo(reactEventProvider) 75 | .listenTo(reactIntentProvider) 76 | .initState(init) 77 | .defaultFallbackState(defaultFallback); 78 | 79 | Configuration botConfiguration = new BaseConfiguration(); 80 | 81 | botConfiguration.setProperty(RECOGNITION_POSTPROCESSORS_KEY,"RemoveEnglishStopWords"); 82 | botConfiguration.setProperty("xatkit.dialogflow.projectId", "YOUR PROJECT ID"); 83 | botConfiguration.setProperty("xatkit.dialogflow.credentials.path", "YOUR CREDENTIALS PATH"); 84 | botConfiguration.setProperty("xatkit.dialogflow.language", "en-US"); 85 | botConfiguration.setProperty("xatkit.dialogflow.clean_on_startup", true); 86 | botConfiguration.setProperty(ENABLE_RECOGNITION_ANALYTICS, false); 87 | 88 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 89 | xatkitBot.run(); 90 | /* 91 | * The bot is now started, you can check http://localhost:5000/admin to test it. 92 | * The logs of the bot are stored in the logs folder at the root of this project. 93 | */ 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/ToxicityDetectorBot/.gitignore: -------------------------------------------------------------------------------- 1 | # Visual code classpath 2 | **/.classpath 3 | **/.factorypath 4 | 5 | # Intellij files 6 | **/.idea 7 | *.iml 8 | 9 | # Eclipse files 10 | .settings 11 | 12 | # VisualCode files 13 | .project 14 | 15 | # Compiled class file 16 | *.class 17 | 18 | # Log file 19 | *.log 20 | 21 | # BlueJ files 22 | *.ctxt 23 | 24 | # Mobile Tools for Java (J2ME) 25 | .mtj.tmp/ 26 | 27 | # Package Files # 28 | *.jar 29 | *.war 30 | *.nar 31 | *.ear 32 | *.zip 33 | *.tar.gz 34 | *.rar 35 | 36 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 37 | hs_err_pid* 38 | 39 | # maven 40 | **/target 41 | **/*.versionsBackup 42 | 43 | # Generated data/ folder 44 | **/data/ 45 | 46 | # Generated public/ folder 47 | **/public/ 48 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/ToxicityDetectorBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | toxicity-detector-bot 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 3.9.1 25 | 26 | 27 | 28 | 29 | jitpack.io 30 | https://jitpack.io 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | com.xatkit 40 | core 41 | 5.0.0-SNAPSHOT 42 | 43 | 44 | 45 | com.xatkit 46 | chat-platform 47 | 3.0.1-SNAPSHOT 48 | 49 | 50 | 51 | com.xatkit 52 | react-platform 53 | 4.0.1-SNAPSHOT 54 | 55 | 56 | 57 | 58 | 59 | org.projectlombok 60 | lombok 61 | 62 | 63 | 64 | 65 | 66 | junit 67 | junit 68 | 69 | 70 | 71 | org.assertj 72 | assertj-core 73 | 74 | 75 | 76 | org.mockito 77 | mockito-core 78 | 79 | 80 | 81 | 82 | 83 | edu.stanford.nlp 84 | stanford-corenlp 85 | 3.9.2 86 | 87 | 88 | com.google.protobuf 89 | protobuf-java 90 | 91 | 92 | 93 | 94 | 95 | edu.stanford.nlp 96 | stanford-corenlp 97 | 3.9.2 98 | models 99 | 100 | 101 | com.google.protobuf 102 | protobuf-java 103 | 104 | 105 | 106 | 107 | 127 | 128 | 129 | com.mashape.unirest 130 | unirest-java 131 | 1.4.9 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | org.projectlombok 143 | lombok 144 | ${lombok.version} 145 | provided 146 | 147 | 148 | 149 | 150 | 151 | junit 152 | junit 153 | ${junit.version} 154 | test 155 | 156 | 157 | 158 | org.assertj 159 | assertj-core 160 | test 161 | ${assertj.version} 162 | 163 | 164 | 165 | org.mockito 166 | mockito-core 167 | ${mockito-version} 168 | test 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | org.apache.maven.plugins 180 | maven-assembly-plugin 181 | ${maven-assembly-plugin.version} 182 | 183 | 184 | package 185 | 186 | single 187 | 188 | 189 | 190 | 191 | 192 | jar-with-dependencies 193 | 194 | 195 | 196 | com.xatkit.example.ToxicityDetectorBot 197 | 198 | 199 | toxicity-detector-bot 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | org.apache.maven.plugins 209 | maven-assembly-plugin 210 | 211 | 212 | 213 | 214 | 215 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/ToxicityDetectorBot/src/main/java/com/xatkit/example/ToxicityDetectorBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.core.XatkitBot; 4 | import com.xatkit.core.recognition.processor.toxicity.detoxify.DetoxifyConfiguration; 5 | import com.xatkit.core.recognition.processor.toxicity.detoxify.DetoxifyScore; 6 | import com.xatkit.core.recognition.processor.toxicity.perspectiveapi.PerspectiveApiConfiguration; 7 | import com.xatkit.core.recognition.processor.toxicity.perspectiveapi.PerspectiveApiScore; 8 | import com.xatkit.plugins.react.platform.ReactPlatform; 9 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 10 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 11 | import lombok.val; 12 | import org.apache.commons.configuration2.BaseConfiguration; 13 | import org.apache.commons.configuration2.Configuration; 14 | 15 | import static com.xatkit.core.recognition.processor.ToxicityPostProcessorConfiguration.USE_DETOXIFY; 16 | import static com.xatkit.core.recognition.processor.ToxicityPostProcessorConfiguration.USE_PERSPECTIVE_API; 17 | import static com.xatkit.dsl.DSL.any; 18 | import static com.xatkit.dsl.DSL.eventIs; 19 | import static com.xatkit.dsl.DSL.fallbackState; 20 | import static com.xatkit.dsl.DSL.intent; 21 | import static com.xatkit.dsl.DSL.intentIs; 22 | import static com.xatkit.dsl.DSL.model; 23 | import static com.xatkit.dsl.DSL.state; 24 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.*; 25 | import static java.util.Objects.nonNull; 26 | 27 | 28 | /** 29 | * This is an example bot which uses ToxicityPostProcessor, designed with Xatkit. 30 | *

31 | * You can check our wiki 32 | * to learn more about bot creation, supported platforms, and advanced usage. 33 | */ 34 | public class ToxicityDetectorBot { 35 | 36 | 37 | public static void main(String[] args) { 38 | 39 | val question = intent("comment") 40 | .trainingSentence("COMMENT") 41 | .parameter("comment").fromFragment("COMMENT").entity(any()); 42 | 43 | ReactPlatform reactPlatform = new ReactPlatform(); 44 | ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform); 45 | ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform); 46 | 47 | val init = state("Init"); 48 | val awaitingInput = state("AwaitingInput"); 49 | val handleWelcome = state("HandleWelcome"); 50 | val handleComment = state("HandleComment"); 51 | 52 | init 53 | .next() 54 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(handleWelcome); 55 | 56 | handleWelcome 57 | .body(context -> reactPlatform.reply(context, 58 | "Hi, I am your favourite bot :) I will score your comments toxicity.")) 59 | .next() 60 | .moveTo(awaitingInput); 61 | 62 | awaitingInput 63 | .next() 64 | .when(intentIs(question)).moveTo(handleComment); 65 | 66 | handleComment 67 | .body(context -> { 68 | PerspectiveApiScore score1 = 69 | (PerspectiveApiScore)context.getIntent().getNlpData().get("nlp.perspectiveapi"); 70 | if(nonNull(score1)) { 71 | /* 72 | * Ignore this part if Perspective API is not enabled for the bot. 73 | */ 74 | Double toxicity1 = score1.getToxicityScore(); 75 | if (!toxicity1.equals(PerspectiveApiScore.DEFAULT_SCORE)) { 76 | reactPlatform.reply(context, 77 | "[PerspectiveAPI] Your comment was " + Math.round(toxicity1 * 100) + "% toxic"); 78 | } else { 79 | reactPlatform.reply(context, "[PerspectiveAPI] Sorry, I can't compute your comment toxicity"); 80 | } 81 | } 82 | DetoxifyScore score2 = 83 | (DetoxifyScore) context.getIntent().getNlpData().get("nlp.detoxify"); 84 | if(nonNull(score2)) { 85 | /* 86 | * Ignore this part if Detoxify is not enabled for the bot. 87 | */ 88 | Double toxicity2 = score2.getToxicityScore(); 89 | if (!toxicity2.equals(DetoxifyScore.DEFAULT_SCORE)) { 90 | reactPlatform.reply(context, 91 | "[Detoxify] Your comment was " + Math.round(toxicity2 * 100) + "% toxic"); 92 | } else { 93 | reactPlatform.reply(context, "[Detoxify] Sorry, I can't compute your comment toxicity"); 94 | } 95 | } 96 | }) 97 | .next() 98 | .moveTo(awaitingInput); 99 | 100 | val defaultFallback = fallbackState() 101 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't get it")); 102 | 103 | val botModel = model() 104 | .usePlatform(reactPlatform) 105 | .listenTo(reactEventProvider) 106 | .listenTo(reactIntentProvider) 107 | .initState(init) 108 | .defaultFallbackState(defaultFallback); 109 | 110 | Configuration botConfiguration = new BaseConfiguration(); 111 | botConfiguration.setProperty(RECOGNITION_POSTPROCESSORS_KEY,"ToxicityPostProcessor"); 112 | botConfiguration.setProperty(USE_PERSPECTIVE_API, true); 113 | botConfiguration.setProperty(PerspectiveApiConfiguration.API_KEY, "YOUR-PERSPECTIVEAPI-KEY"); 114 | botConfiguration.setProperty(PerspectiveApiConfiguration.LANGUAGE, "en"); 115 | botConfiguration.setProperty(USE_DETOXIFY, true); 116 | botConfiguration.setProperty(DetoxifyConfiguration.DETOXIFY_SERVER_URL, "YOUR-SERVER-URL"); 117 | botConfiguration.setProperty("xatkit.dialogflow.projectId", "YOUR-PROJECT-ID"); 118 | botConfiguration.setProperty("xatkit.dialogflow.credentials.path", "YOUR-CREDENTIALS-PATH"); 119 | botConfiguration.setProperty("xatkit.dialogflow.language", "en-US"); 120 | botConfiguration.setProperty("xatkit.dialogflow.clean_on_startup", true); 121 | botConfiguration.setProperty(ENABLE_RECOGNITION_ANALYTICS, false); 122 | 123 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 124 | xatkitBot.run(); 125 | /* 126 | * The bot is now started, you can check http://localhost:5000/admin to test it. 127 | * The logs of the bot are stored in the logs folder at the root of this project. 128 | */ 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/YesNoAndSentimentBot/.gitignore: -------------------------------------------------------------------------------- 1 | # Visual code classpath 2 | **/.classpath 3 | **/.factorypath 4 | 5 | # Intellij files 6 | **/.idea 7 | *.iml 8 | 9 | # Eclipse files 10 | .settings 11 | 12 | # VisualCode files 13 | .project 14 | 15 | # Compiled class file 16 | *.class 17 | 18 | # Log file 19 | *.log 20 | 21 | # BlueJ files 22 | *.ctxt 23 | 24 | # Mobile Tools for Java (J2ME) 25 | .mtj.tmp/ 26 | 27 | # Package Files # 28 | *.jar 29 | *.war 30 | *.nar 31 | *.ear 32 | *.zip 33 | *.tar.gz 34 | *.rar 35 | 36 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 37 | hs_err_pid* 38 | 39 | # maven 40 | **/target 41 | **/*.versionsBackup 42 | 43 | # Generated data/ folder 44 | **/data/ 45 | 46 | # Generated public/ folder 47 | **/public/ 48 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/YesNoAndSentimentBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | yesno-sentiment-bot 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.12 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 3.9.1 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.xatkit 33 | core 34 | 5.0.0-SNAPSHOT 35 | 36 | 37 | 38 | com.xatkit 39 | chat-platform 40 | 3.0.1-SNAPSHOT 41 | 42 | 43 | 44 | com.xatkit 45 | react-platform 46 | 4.0.1-SNAPSHOT 47 | 48 | 49 | 50 | 51 | 52 | org.projectlombok 53 | lombok 54 | 55 | 56 | 57 | 58 | 59 | junit 60 | junit 61 | 62 | 63 | 64 | org.assertj 65 | assertj-core 66 | 67 | 68 | 69 | org.mockito 70 | mockito-core 71 | 72 | 73 | 74 | 75 | 76 | edu.stanford.nlp 77 | stanford-corenlp 78 | 3.9.2 79 | 80 | 81 | com.google.protobuf 82 | protobuf-java 83 | 84 | 85 | 86 | 87 | 88 | edu.stanford.nlp 89 | stanford-corenlp 90 | 3.9.2 91 | models 92 | 93 | 94 | com.google.protobuf 95 | protobuf-java 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | org.projectlombok 109 | lombok 110 | ${lombok.version} 111 | provided 112 | 113 | 114 | 115 | 116 | 117 | junit 118 | junit 119 | ${junit.version} 120 | test 121 | 122 | 123 | 124 | org.assertj 125 | assertj-core 126 | test 127 | ${assertj.version} 128 | 129 | 130 | 131 | org.mockito 132 | mockito-core 133 | ${mockito-version} 134 | test 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | org.apache.maven.plugins 146 | maven-assembly-plugin 147 | ${maven-assembly-plugin.version} 148 | 149 | 150 | package 151 | 152 | single 153 | 154 | 155 | 156 | 157 | 158 | jar-with-dependencies 159 | 160 | 161 | 162 | com.xatkit.example.YesNoAndSentimentBot 163 | 164 | 165 | yesno-sentiment-bot 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | org.apache.maven.plugins 175 | maven-assembly-plugin 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /LanguageProcessorsBots/YesNoAndSentimentBot/src/main/java/com/xatkit/example/YesNoAndSentimentBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.core.XatkitBot; 4 | import com.xatkit.plugins.react.platform.ReactPlatform; 5 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 6 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 7 | import lombok.val; 8 | import org.apache.commons.configuration2.BaseConfiguration; 9 | import org.apache.commons.configuration2.Configuration; 10 | 11 | import static com.xatkit.dsl.DSL.any; 12 | import static com.xatkit.dsl.DSL.eventIs; 13 | import static com.xatkit.dsl.DSL.fallbackState; 14 | import static com.xatkit.dsl.DSL.intent; 15 | import static com.xatkit.dsl.DSL.intentIs; 16 | import static com.xatkit.dsl.DSL.model; 17 | import static com.xatkit.dsl.DSL.state; 18 | import static com.xatkit.core.recognition.IntentRecognitionProviderFactoryConfiguration.*; 19 | 20 | import java.util.Random; 21 | 22 | /** 23 | * This is an example bot which uses IsEnglishYesNoQuestion and EnglishSentiment postprocessors, designed with Xatkit. 24 | *

25 | * You can check our wiki 26 | * to learn more about bot creation, supported platforms, and advanced usage. 27 | */ 28 | public class YesNoAndSentimentBot { 29 | 30 | public static void main(String[] args) { 31 | 32 | val question = intent("Question") 33 | .trainingSentence("QUESTION?") 34 | .parameter("question").fromFragment("QUESTION").entity(any()); 35 | 36 | val affirmation = intent("Affirmation") 37 | .trainingSentence("AFFIRMATION") 38 | .parameter("affirmation").fromFragment("AFFIRMATION").entity(any()); 39 | 40 | ReactPlatform reactPlatform = new ReactPlatform(); 41 | ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform); 42 | ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform); 43 | 44 | val init = state("Init"); 45 | val awaitingInput = state("AwaitingInput"); 46 | val handleWelcome = state("HandleWelcome"); 47 | val handleQuestion = state("HandleQuestion"); 48 | val handleAffirmation = state("HandleAffirmation"); 49 | 50 | init 51 | .next() 52 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(handleWelcome); 53 | 54 | handleWelcome 55 | .body(context -> reactPlatform.reply(context, 56 | "Hi, I am your favourite bot :) I can answer yes/no questions and be your psychologist!")) 57 | .next() 58 | .moveTo(awaitingInput); 59 | 60 | awaitingInput 61 | .next() 62 | .when(intentIs(question)).moveTo(handleQuestion) 63 | .when(intentIs(affirmation)).moveTo(handleAffirmation); 64 | 65 | handleQuestion 66 | .body(context -> { 67 | Boolean isYesNo = (Boolean) context.getIntent().getNlpData().get("nlp.stanford.isYesNo"); 68 | if (isYesNo) { 69 | Random rd = new Random(); 70 | String answer; 71 | if (rd.nextBoolean()) { 72 | answer = "Yes."; 73 | } 74 | else { 75 | answer = "No."; 76 | } 77 | reactPlatform.reply(context, answer); 78 | } 79 | else { 80 | reactPlatform.reply(context, "Sorry, I only answer yes/no questions."); 81 | } 82 | }) 83 | .next() 84 | .moveTo(awaitingInput); 85 | 86 | handleAffirmation 87 | .body(context -> { 88 | String sentiment = (String) context.getIntent().getNlpData().get("nlp.stanford.sentiment"); 89 | reactPlatform.reply(context, "You have a " + sentiment.toLowerCase() + " attitude."); 90 | }) 91 | .next() 92 | .moveTo(awaitingInput); 93 | 94 | val defaultFallback = fallbackState() 95 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't get it")); 96 | 97 | val botModel = model() 98 | .usePlatform(reactPlatform) 99 | .listenTo(reactEventProvider) 100 | .listenTo(reactIntentProvider) 101 | .initState(init) 102 | .defaultFallbackState(defaultFallback); 103 | 104 | Configuration botConfiguration = new BaseConfiguration(); 105 | 106 | botConfiguration.addProperty(RECOGNITION_POSTPROCESSORS_KEY, 107 | "IsEnglishYesNoQuestion, EnglishSentiment"); 108 | botConfiguration.setProperty("xatkit.dialogflow.projectId", "YOUR PROJECT ID"); 109 | botConfiguration.setProperty("xatkit.dialogflow.credentials.path", "YOUR CREDENTIALS FILE PATH"); 110 | botConfiguration.setProperty("xatkit.dialogflow.language", "en-US"); 111 | botConfiguration.setProperty("xatkit.dialogflow.clean_on_startup", true); 112 | botConfiguration.setProperty(ENABLE_RECOGNITION_ANALYTICS, false); 113 | 114 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 115 | xatkitBot.run(); 116 | /* 117 | * The bot is now started, you can check http://localhost:5000/admin to test it. 118 | * The logs of the bot are stored in the logs folder at the root of this project. 119 | */ 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /MessengerBotBasic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.xatkit 9 | 10 | messenger-bot-basic-example 11 | 12 | 1.0.0-SNAPSHOT 13 | 14 | jar 15 | 16 | 17 | 18 | 19 | 20 | 1.8 21 | 22 | 1.8 23 | 24 | UTF-8 25 | 26 | 3.1.0 27 | 28 | 3.2.0 29 | 30 | 4.13.1 31 | 32 | 3.14.0 33 | 34 | 3.3.3 35 | 36 | 1.18.12 37 | 38 | 1.24.1 39 | 40 | 1.24.1 41 | 42 | 1.4.9 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | com.xatkit 57 | 58 | core 59 | 60 | 5.0.0-SNAPSHOT 61 | 62 | 63 | 64 | 65 | 66 | 67 | com.xatkit 68 | 69 | rest-platform 70 | 71 | 2.0.0-SNAPSHOT 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | com.xatkit 80 | 81 | messenger-platform-runtime 82 | 83 | 0.1.0 84 | 85 | 86 | 87 | 88 | com.xatkit 89 | react-platform 90 | 4.0.1-SNAPSHOT 91 | 92 | 93 | 94 | com.xatkit 95 | slack-platform 96 | 3.0.1-SNAPSHOT 97 | 98 | 99 | 100 | com.xatkit 101 | chat-platform 102 | 3.0.1-SNAPSHOT 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | org.projectlombok 112 | 113 | lombok 114 | 115 | 116 | 117 | 118 | 119 | 120 | org.apache.tika 121 | 122 | tika-core 123 | 124 | 125 | 126 | 127 | 128 | 129 | org.apache.tika 130 | 131 | tika-parsers 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | junit 142 | 143 | junit 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | org.assertj 152 | 153 | assertj-core 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | org.mockito 162 | 163 | mockito-core 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | org.projectlombok 184 | 185 | lombok 186 | 187 | ${lombok.version} 188 | 189 | provided 190 | 191 | 192 | 193 | 194 | 195 | org.apache.tika 196 | 197 | tika-core 198 | 199 | ${tika-core.version} 200 | 201 | compile 202 | 203 | 204 | 205 | 206 | 207 | org.apache.tika 208 | 209 | tika-parsers 210 | 211 | ${tika-parsers.version} 212 | 213 | compile 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | junit 223 | 224 | junit 225 | 226 | ${junit.version} 227 | 228 | test 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | org.assertj 237 | 238 | assertj-core 239 | 240 | test 241 | 242 | ${assertj.version} 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | org.mockito 251 | 252 | mockito-core 253 | 254 | ${mockito-version} 255 | 256 | test 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | org.apache.maven.plugins 281 | 282 | maven-assembly-plugin 283 | 284 | ${maven-assembly-plugin.version} 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | package 294 | 295 | 296 | 297 | 298 | 299 | single 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | jar-with-dependencies 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | com.xatkit.example.MessengerBotBasic 328 | 329 | 330 | 331 | 332 | 333 | messenger-basic-bot 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | org.apache.maven.plugins 351 | 352 | maven-assembly-plugin 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | -------------------------------------------------------------------------------- /MessengerBotBasic/src/main/java/com/xatkit/example/FileManager.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.plugins.messenger.platform.entity.Attachment; 4 | import com.xatkit.plugins.messenger.platform.entity.File; 5 | import fr.inria.atlanmod.commons.log.Log; 6 | import org.apache.commons.io.FilenameUtils; 7 | import org.apache.tika.Tika; 8 | 9 | import java.io.*; 10 | import java.net.URLConnection; 11 | import java.text.MessageFormat; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | public class FileManager { 16 | 17 | private static FileManager fileManager; 18 | private Map files; 19 | 20 | private FileManager() { 21 | this.files = new HashMap<>(); 22 | } 23 | 24 | public static FileManager get() { 25 | Log.debug("Returning FileManager"); 26 | if (fileManager == null) { 27 | Log.debug("FileManager not found, creating new FileManager."); 28 | fileManager = new FileManager(); 29 | } 30 | return fileManager; 31 | } 32 | 33 | public File loadFileToName(Attachment.AttachmentType type, String fileName, String name) throws IOException { 34 | InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName); 35 | if (inputStream == null) { 36 | String msg = MessageFormat.format("{0} not found.",fileName); 37 | Log.error(msg); 38 | throw new FileNotFoundException(msg); 39 | } 40 | 41 | Tika tika = new Tika(); 42 | String mimeType = tika.detect(inputStream); 43 | if (mimeType == null) mimeType = tika.detect(fileName); 44 | if (mimeType == null) mimeType = URLConnection.guessContentTypeFromStream(inputStream); 45 | if (mimeType == null) mimeType = URLConnection.guessContentTypeFromName(fileName); 46 | 47 | //https://stackoverflow.com/a/35465681 48 | java.io.File tempFile = java.io.File.createTempFile(String.valueOf(inputStream.hashCode()), FilenameUtils.getExtension(fileName)); 49 | tempFile.deleteOnExit(); 50 | 51 | FileOutputStream fileOutputStream = new FileOutputStream(tempFile); 52 | byte[] buffer = new byte[1024]; 53 | int bytesRead; 54 | while ((bytesRead = inputStream.read(buffer)) != -1) { 55 | fileOutputStream.write(buffer, 0, bytesRead); 56 | } 57 | inputStream.close(); 58 | fileOutputStream.close(); 59 | 60 | File file = new File(type, tempFile, mimeType); 61 | files.put(name, file); 62 | return getFile(name); 63 | } 64 | 65 | public File getFile(String name) { 66 | File file = null; 67 | if (files.containsKey(name)) file = files.get(name); 68 | else Log.error("Attempted to use a file by the name \"{0}\", but it is not loaded.", name); 69 | return file; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /MessengerBotBasic/src/main/java/com/xatkit/example/PropertiesManager.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import fr.inria.atlanmod.commons.log.Log; 4 | 5 | import java.io.FileNotFoundException; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.text.MessageFormat; 9 | import java.util.Properties; 10 | 11 | public class PropertiesManager { 12 | 13 | private static PropertiesManager propertiesManager; 14 | private final Properties properties = new Properties(); 15 | private final String propertiesDefaultFileName = "bot-private.properties"; 16 | 17 | private PropertiesManager() throws IOException { 18 | readProperties(); 19 | } 20 | 21 | public static PropertiesManager get() throws IOException { 22 | Log.debug("Returning PropertiesManager"); 23 | if (propertiesManager == null) { 24 | Log.debug("PropertiesManager not found, creating new PropertiesManager."); 25 | propertiesManager = new PropertiesManager(); 26 | } 27 | return propertiesManager; 28 | } 29 | 30 | private void readProperties() throws IOException { 31 | readProperties(propertiesDefaultFileName); 32 | } 33 | 34 | private void readProperties(String fileName) throws IOException { 35 | InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName); 36 | 37 | if (inputStream == null) { 38 | String msg = MessageFormat.format("{0} not found.",fileName); 39 | Log.error(msg); 40 | throw new FileNotFoundException(msg); 41 | } 42 | 43 | properties.load(inputStream); 44 | } 45 | 46 | public String getValue(String key) { 47 | return properties.getProperty(key); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /MessengerBotBasic/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /MessengerBotBasic/src/main/resources/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xatkit-bot-platform/xatkit-examples/12d71c838f0d1e8c0dd2038a2839fe6bd1c4b2b9/MessengerBotBasic/src/main/resources/pic.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Xatkit Examples 2 | 3 | [![Wiki Badge](https://img.shields.io/badge/doc-wiki-blue)](https://github.com/xatkit-bot-platform/xatkit-releases/wiki) 4 | 5 | Example Bots built with the Xatkit framework 6 | 7 | ## Installation 8 | 9 | The bots in this repository work with the [latest version of Xatkit](https://github.com/xatkit-bot-platform/xatkit), unless stated explicitly in the bot directory's README. Installing the Eclipse plugins is not required to execute the bot, but needed to open/edit their execution models and intent libraries with the Xatkit language auto-completion, syntax highlighting and other advanced IDE features. 10 | 11 | ## Running a Bot Example 12 | 13 | These example bots are run as any other bot. You can read [our getting started guide](https://github.com/xatkit-bot-platform/xatkit/wiki/Getting-Started) 14 | and our instructions for [configuring](https://github.com/xatkit-bot-platform/xatkit/wiki/Xatkit-Options) and deploying bots, e.g. in 15 | [Slack](https://github.com/xatkit-bot-platform/xatkit/wiki/Deploying-on-Slack) if needed. More info on [our wiki](https://github.com/xatkit-bot-platform/xatkit/wiki). 16 | 17 | Make sure you take the time to read the documentation corresponding to the platform/s used by the bot before trying to run it. 18 | 19 | If you have any issue to run your bot do not hesitate to report is on our [issue tracker](https://github.com/xatkit-bot-platform/xatkit-examples/issues)! 20 | 21 | ## List of sample bots 22 | 23 | This repository includes a diverse set of bot examples, from simple bots to Greet you to bots that allow you *talk* with GitHub repos, create diagrams or automatically create Trello cards. 24 | 25 | A complete list of bots and full technical details behind some of them is available in the [Xatkit Examples page](https://xatkit.com/chatbot-examples/). 26 | 27 | 28 | ## Contribute your own examples 29 | 30 | Have you created any cool bot with Xatkit? Let us know and we'll be happy to include in the list! 31 | 32 | 33 | -------------------------------------------------------------------------------- /SimpleQABot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | simple-qa-bot-example 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 1.4.9 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.xatkit 33 | core 34 | 5.0.0-SNAPSHOT 35 | 36 | 37 | 38 | com.xatkit 39 | chat-platform 40 | 3.0.1-SNAPSHOT 41 | 42 | 43 | 44 | com.xatkit 45 | react-platform 46 | 4.0.1-SNAPSHOT 47 | 48 | 49 | 50 | 51 | 52 | org.projectlombok 53 | lombok 54 | 55 | 56 | 57 | 58 | 59 | junit 60 | junit 61 | 62 | 63 | 64 | org.assertj 65 | assertj-core 66 | 67 | 68 | 69 | org.mockito 70 | mockito-core 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.projectlombok 82 | lombok 83 | ${lombok.version} 84 | provided 85 | 86 | 87 | 88 | 89 | 90 | junit 91 | junit 92 | ${junit.version} 93 | test 94 | 95 | 96 | 97 | org.assertj 98 | assertj-core 99 | test 100 | ${assertj.version} 101 | 102 | 103 | 104 | org.mockito 105 | mockito-core 106 | ${mockito-version} 107 | test 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.apache.maven.plugins 119 | maven-assembly-plugin 120 | ${maven-assembly-plugin.version} 121 | 122 | 123 | package 124 | 125 | single 126 | 127 | 128 | 129 | 130 | 131 | jar-with-dependencies 132 | 133 | 134 | 135 | com.xatkit.example.SimpleQABot 136 | 137 | 138 | simple-qa-bot 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | org.apache.maven.plugins 148 | maven-assembly-plugin 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /SimpleQABot/src/main/java/com/xatkit/example/SimpleQABot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.xatkit.core.XatkitBot; 4 | import com.xatkit.library.core.CoreLibrary; 5 | import com.xatkit.plugins.react.platform.ReactPlatform; 6 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 7 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 8 | import lombok.val; 9 | import org.apache.commons.configuration2.BaseConfiguration; 10 | import org.apache.commons.configuration2.Configuration; 11 | 12 | import static com.xatkit.dsl.DSL.eventIs; 13 | import static com.xatkit.dsl.DSL.fallbackState; 14 | import static com.xatkit.dsl.DSL.intent; 15 | import static com.xatkit.dsl.DSL.intentIs; 16 | import static com.xatkit.dsl.DSL.model; 17 | import static com.xatkit.dsl.DSL.state; 18 | 19 | public class SimpleQABot { 20 | 21 | /* 22 | * Your bot is a plain Java application: you need to define a main method to make the created jar executable. 23 | */ 24 | public static void main(String[] args) { 25 | 26 | /* 27 | * Define the intents our bot will react to. 28 | */ 29 | val xatkitInfo = intent("XatkitInfo") 30 | .trainingSentence("What is Xatkit?"); 31 | 32 | val wantBot = intent("WantBot") 33 | .trainingSentence("I want a bot"); 34 | 35 | 36 | /* 37 | * Instantiate the platforms we will use in the bot definition. 38 | */ 39 | ReactPlatform reactPlatform = new ReactPlatform(); 40 | /* 41 | * Similarly, instantiate the intent/event providers we want to use. 42 | */ 43 | ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform); 44 | ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform); 45 | 46 | /* 47 | * Create the states we want to use in our bot. 48 | */ 49 | val init = state("Init"); 50 | val greetUser = state("GreetUser"); 51 | val awaitingInput = state("AwaitingInput"); 52 | val handleGreetings = state("HandleGreetings"); 53 | val giveInfo = state("GiveInfo"); 54 | val askBotSize = state("AskBotSize"); 55 | val answerSmallBot = state("AnswerSmallBot"); 56 | val answerBigBot = state("AnswerBigBot"); 57 | 58 | /* 59 | * Specify the content of the bot states (i.e. the behavior of the bot). 60 | */ 61 | init 62 | .next() 63 | /* 64 | * We check that the received event matches the ClientReady event defined in the 65 | * ReactEventProvider. The list of events defined in a provider is available in the provider's 66 | * wiki page. 67 | */ 68 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(greetUser); 69 | 70 | greetUser 71 | .body(context -> reactPlatform.reply(context, "Hi, I can help you, ask me a question!")) 72 | .next() 73 | .moveTo(awaitingInput); 74 | 75 | awaitingInput 76 | .next() 77 | /* 78 | * The Xatkit DSL offers dedicated predicates (intentIs(IntentDefinition) and eventIs 79 | * (EventDefinition) to check received intents/events. 80 | *

81 | * You can also check a condition over the underlying bot state using the following syntax: 82 | *

 83 |                  * {@code
 84 |                  * .when(context -> [condition manipulating the context]).moveTo(state);
 85 |                  * }
 86 |                  * 
87 | */ 88 | .when(intentIs(CoreLibrary.Greetings)).moveTo(handleGreetings) 89 | .when(intentIs(xatkitInfo)).moveTo(giveInfo) 90 | .when(intentIs(wantBot)).moveTo(askBotSize); 91 | 92 | 93 | handleGreetings 94 | .body(context -> reactPlatform.reply(context, "Hi, what can I do for you?")) 95 | .next() 96 | .moveTo(awaitingInput); 97 | 98 | giveInfo 99 | .body(context -> reactPlatform.reply(context, "It's an amazing platform!")) 100 | .next() 101 | .moveTo(awaitingInput); 102 | 103 | askBotSize 104 | .body(context -> reactPlatform.reply(context, "Sure, how many intents do you want?")) 105 | .next() 106 | .when(intentIs(CoreLibrary.NumberValue).and(context -> { 107 | int numberOfIntents = Integer.parseInt((String) context.getIntent().getValue("value")); 108 | return numberOfIntents <= 10; 109 | })).moveTo(answerSmallBot) 110 | .when(intentIs(CoreLibrary.NumberValue).and(context -> { 111 | int numberOfIntents = Integer.parseInt((String) context.getIntent().getValue("value")); 112 | return numberOfIntents > 10; 113 | })).moveTo(answerBigBot) 114 | .fallback(context -> { 115 | int retries = (Integer) context.getSession().getOrDefault("botsize.fallback", 0); 116 | retries++; 117 | context.getSession().put("botsize.fallback", retries); 118 | if(retries < 3) { 119 | reactPlatform.reply(context, "Sorry I didn't get it, could you give me a number?"); 120 | } else { 121 | reactPlatform.reply(context, "Maybe you don't know what's a number ..."); 122 | reactPlatform.reply(context, "Anyway, I am done with you, come back when you'll have a number" + 123 | " to give"); 124 | } 125 | 126 | }); 127 | 128 | answerSmallBot 129 | .body(context -> reactPlatform.reply(context, "It's 10$!")) 130 | .next() 131 | .moveTo(awaitingInput); 132 | 133 | answerBigBot 134 | .body(context -> reactPlatform.reply(context, "It's 100000$!")) 135 | .next() 136 | .moveTo(awaitingInput); 137 | 138 | /* 139 | * The state that is executed if the engine doesn't find any navigable transition in a state and the state 140 | * doesn't contain a fallback. 141 | */ 142 | val defaultFallback = fallbackState() 143 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't, get it")); 144 | 145 | /* 146 | * Creates the bot model that will be executed by the Xatkit engine. 147 | *

148 | * A bot model contains: 149 | * - A list of intents/events (or libraries) used by the bot. This allows to register the events/intents to the NLP 150 | * service. 151 | * - A list of platforms used by the bot. Xatkit will take care of starting and initializing the platforms 152 | * when starting the bot. 153 | * - A list of providers the bot should listen to for events/intents. As for the platforms Xatkit will take 154 | * care of initializing the provider when starting the bot. 155 | * - The list of states the compose the bot (this list can contain the init/fallback state, but it is optional) 156 | * - The entry point of the bot (a.k.a init state) 157 | * - The default fallback state: the state that is executed if the engine doesn't find any navigable 158 | * transition in a state and the state doesn't contain a fallback. 159 | */ 160 | val botModel = model() 161 | .useIntent(CoreLibrary.Greetings) 162 | .useIntent(xatkitInfo) 163 | .useIntent(wantBot) 164 | .useIntent(CoreLibrary.NumberValue) 165 | .usePlatform(reactPlatform) 166 | .listenTo(reactEventProvider) 167 | .listenTo(reactIntentProvider) 168 | .useState(greetUser) 169 | .useState(awaitingInput) 170 | .useState(handleGreetings) 171 | .useState(giveInfo) 172 | .useState(askBotSize) 173 | .useState(answerSmallBot) 174 | .useState(answerBigBot) 175 | .initState(init) 176 | .defaultFallbackState(defaultFallback); 177 | 178 | Configuration botConfiguration = new BaseConfiguration(); 179 | /* 180 | * Add configuration properties (e.g. authentication tokens, platform tuning, intent provider to use). 181 | * Check the corresponding platform's wiki page for further information on optional/mandatory parameters and 182 | * their values. 183 | */ 184 | 185 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 186 | xatkitBot.run(); 187 | /* 188 | * The bot is now started, you can check http://localhost:5000/admin to test it. 189 | * The logs of the bot are stored in the logs folder at the root of this project. 190 | */ 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /WeatherBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | weather-bot-example 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.13.1 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 1.4.9 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | com.xatkit 33 | core 34 | 5.0.0-SNAPSHOT 35 | 36 | 37 | 38 | com.xatkit 39 | chat-platform 40 | 3.0.1-SNAPSHOT 41 | 42 | 43 | 44 | com.xatkit 45 | react-platform 46 | 4.0.1-SNAPSHOT 47 | 48 | 49 | 50 | com.xatkit 51 | rest-platform 52 | 2.0.0-SNAPSHOT 53 | 54 | 55 | 56 | 57 | 58 | org.projectlombok 59 | lombok 60 | 61 | 62 | 63 | 64 | 65 | junit 66 | junit 67 | 68 | 69 | 70 | org.assertj 71 | assertj-core 72 | 73 | 74 | 75 | org.mockito 76 | mockito-core 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.projectlombok 88 | lombok 89 | ${lombok.version} 90 | provided 91 | 92 | 93 | 94 | 95 | 96 | junit 97 | junit 98 | ${junit.version} 99 | test 100 | 101 | 102 | 103 | org.assertj 104 | assertj-core 105 | test 106 | ${assertj.version} 107 | 108 | 109 | 110 | org.mockito 111 | mockito-core 112 | ${mockito-version} 113 | test 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | org.apache.maven.plugins 125 | maven-assembly-plugin 126 | ${maven-assembly-plugin.version} 127 | 128 | 129 | package 130 | 131 | single 132 | 133 | 134 | 135 | 136 | 137 | jar-with-dependencies 138 | 139 | 140 | 141 | com.xatkit.example.WeatherBot 142 | 143 | 144 | weather-bot 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | org.apache.maven.plugins 154 | maven-assembly-plugin 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /WeatherBot/src/main/java/com/xatkit/example/WeatherBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.xatkit.core.XatkitBot; 5 | import com.xatkit.plugins.react.platform.ReactPlatform; 6 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 7 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 8 | import com.xatkit.plugins.rest.platform.RestPlatform; 9 | import com.xatkit.plugins.rest.platform.utils.ApiResponse; 10 | import lombok.val; 11 | import org.apache.commons.configuration2.BaseConfiguration; 12 | import org.apache.commons.configuration2.Configuration; 13 | 14 | import java.text.MessageFormat; 15 | import java.util.Collections; 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import static com.xatkit.dsl.DSL.city; 20 | import static com.xatkit.dsl.DSL.eventIs; 21 | import static com.xatkit.dsl.DSL.fallbackState; 22 | import static com.xatkit.dsl.DSL.intent; 23 | import static com.xatkit.dsl.DSL.intentIs; 24 | import static com.xatkit.dsl.DSL.model; 25 | import static com.xatkit.dsl.DSL.state; 26 | 27 | public class WeatherBot { 28 | 29 | public static void main(String[] args) { 30 | 31 | val howIsTheWeather = intent("HowIsTheWeather") 32 | .trainingSentence("How is the weather today in CITY?") 33 | .trainingSentence("What is the forecast for today in CITY?") 34 | .parameter("cityName").fromFragment("CITY").entity(city()); 35 | 36 | 37 | ReactPlatform reactPlatform = new ReactPlatform(); 38 | RestPlatform restPlatform = new RestPlatform(); 39 | ReactEventProvider reactEventProvider = reactPlatform.getReactEventProvider(); 40 | ReactIntentProvider reactIntentProvider = reactPlatform.getReactIntentProvider(); 41 | 42 | val init = state("Init"); 43 | val awaitingInput = state("AwaitingInput"); 44 | val printWeather = state("PrintWeather"); 45 | 46 | init 47 | .next() 48 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(awaitingInput); 49 | 50 | 51 | awaitingInput 52 | .next() 53 | .when(intentIs(howIsTheWeather)).moveTo(printWeather); 54 | 55 | printWeather 56 | .body(context -> { 57 | String cityName = (String) context.getIntent().getValue("cityName"); 58 | Map queryParameters = new HashMap<>(); 59 | queryParameters.put("q", cityName); 60 | ApiResponse response = restPlatform.getJsonRequest(context, "http://api" + 61 | ".openweathermap.org/data/2.5/weather", queryParameters, Collections.emptyMap(), 62 | Collections.emptyMap()); 63 | if (response.getStatus() == 200) { 64 | long temp = Math.round(response.getBody().getAsJsonObject().get("main").getAsJsonObject().get( 65 | "temp").getAsDouble()); 66 | long tempMin = 67 | Math.round(response.getBody().getAsJsonObject().get("main").getAsJsonObject().get( 68 | "temp_min").getAsDouble()); 69 | long tempMax = 70 | Math.round(response.getBody().getAsJsonObject().get("main").getAsJsonObject().get( 71 | "temp_max").getAsDouble()); 72 | String weather = 73 | response.getBody().getAsJsonObject().get("weather").getAsJsonArray().get(0).getAsJsonObject().get("description").getAsString(); 74 | String weatherIcon = 75 | "http://openweathermap.org/img/wn/" + response.getBody().getAsJsonObject().get( 76 | "weather").getAsJsonArray().get(0).getAsJsonObject().get("icon").getAsString() + ".png"; 77 | reactPlatform.reply(context, MessageFormat.format("The current weather is {0} °C with " + 78 | "{1} ![{1}]({2}) with a high of {3} °C and a low of {4} °C", temp, 79 | weather, 80 | weatherIcon, tempMax, tempMin)); 81 | } else if (response.getStatus() == 400) { 82 | reactPlatform.reply(context, "Oops, I couldn't find this city"); 83 | } else { 84 | reactPlatform.reply(context, "Sorry, an error " + response.getStatus() + " " + response.getStatusText() + " occurred when accessing the openweathermap service"); 85 | } 86 | 87 | }) 88 | .next() 89 | .moveTo(awaitingInput); 90 | 91 | 92 | val defaultFallback = fallbackState() 93 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't, get it")); 94 | 95 | val botModel = model() 96 | .usePlatform(reactPlatform) 97 | .usePlatform(restPlatform) 98 | .listenTo(reactEventProvider) 99 | .listenTo(reactIntentProvider) 100 | .initState(init) 101 | .defaultFallbackState(defaultFallback); 102 | 103 | Configuration botConfiguration = new BaseConfiguration(); 104 | botConfiguration.addProperty("xatkit.message.delay", 500); 105 | botConfiguration.addProperty("xatkit.rest.default.query.parameters", "units=Metric&appid=XXX"); 106 | 107 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 108 | xatkitBot.run(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /YoutubeBot/README.md: -------------------------------------------------------------------------------- 1 | # Xatkit Bot YouTube 2 | This bot can search YouTube videos for you. You only need to ask him to search videos about whatever you want. 3 | 4 | It uses [Dialogflow](https://dialogflow.cloud.google.com) as NLP engine and [Youtube Data API v3](https://developers.google.com/youtube/v3) to request Youtube contents. 5 | 6 | Visit the [xatkit wiki](https://github.com/xatkit-bot-platform/xatkit/wiki) for more info about Xatkit! 7 | 8 | ![Youtube Bot preview](docs/img/preview.gif) 9 | 10 | ## Build the bot 11 | 1- [Build the latest version of Xatkit](https://github.com/xatkit-bot-platform/xatkit/wiki/Build-Xatkit) 12 | 13 | 2- Navigate to `xatkit-examples/` and clone this repository 14 | 15 | 3- [Create a Dialogflow agent](https://github.com/xatkit-bot-platform/xatkit/wiki/Integrating-DialogFlow) to use it with the bot. 16 | 17 | When you configure Xatkit, make sure you edit these lines on [YoutubeBot.java](/src/main/java/com/xatkit/example/YoutubeBot.java) 18 | ```java 19 | botConfiguration.setProperty("xatkit.dialogflow.projectId", "YOUR PROJECT ID"); 20 | botConfiguration.setProperty("xatkit.dialogflow.credentials.path", "PATH TO YOUR DIALOGFLOW CREDENTIALS"); 21 | ``` 22 | 23 | 4- [Get authorization credentials for the Youtube Data API v3](https://developers.google.com/youtube/registering_an_application). For this application it is not needed to obtain OAuth 2.0 credentials since the app does not have access to your Youtube information (it does not modify your account content). Make sure you obtain an API key. 24 | 25 | 5- Once you have your API key, edit these code lines in [YoutubeAPI.java](/src/main/java/com/xatkit/example/YoutubeAPI.java) 26 | ```java 27 | private static final String DEVELOPER_KEY = "YOUR API KEY"; 28 | private static final String APPLICATION_NAME = "YOUR APP NAME"; 29 | ``` 30 | :warning: **API keys are private and you must not publish them in a public repository!** 31 | 32 | ## Start the bot 33 | 34 | Navigate to `xatkit-examples/xatkit-youtube-bot` and start the digital assistant (a web-based bot) 35 | 36 | ```bash 37 | mvn clean compile 38 | mvn exec:java -Dexec.mainClass="com.xatkit.example.YoutubeBot" 39 | ``` 40 | 41 | The console will log some initialization information, and after a few seconds you should see the following message: 42 | 43 | ```bash 44 | INFO - Xatkit bot started 45 | ``` 46 | 47 | Open your browser and navigate to http://localhost:5000/admin and start chatting with your bot! 48 | 49 | ## Editing the bot (optional) 50 | 51 | Feel free to modify the bot however you want him to act. For instance, you can modify the training sentences of the "search" intent of the bot 52 | 53 | ```java 54 | val search = intent("Search") 55 | .trainingSentence("Search KEYWORD") 56 | .trainingSentence("Search NUM videos of KEYWORD") 57 | .trainingSentence("Search NUM videos about KEYWORD") 58 | .trainingSentence("Give me KEYWORD") 59 | .trainingSentence("Give me NUM videos of KEYWORD") 60 | .trainingSentence("Give me NUM videos about KEYWORD") 61 | .trainingSentence("Search KEYWORD and give me NUM videos") 62 | .parameter("keyword").fromFragment("KEYWORD").entity(any()) 63 | .parameter("num").fromFragment("NUM").entity(integer()); 64 | ``` 65 | Remember that you don't need to use these explicit sentences when talking to the bot. Dialogflow uses Machine Learning to infer the training sentence you are referring to! 66 | 67 | ## Troubleshooting 68 | 69 | - IntelliJ error: `java: incompatible types: com.xatkit.dsl.intent.IntentOptionalTrainingSentenceStep cannot be converted to lombok.val` ➡ You need to enable annotation processing in your project (see image below). 70 | ![Enable annotation processing in IntelliJ](docs/img/enable_annotation_processing_intellij.png) 71 | 72 | 73 | # Website 74 | 75 | [xatkit.com](https://xatkit.com/) 76 | 77 | # Author 78 | 79 | [Marcos Gomez Vazquez](https://github.com/mgv99) 80 | -------------------------------------------------------------------------------- /YoutubeBot/docs/img/enable_annotation_processing_intellij.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xatkit-bot-platform/xatkit-examples/12d71c838f0d1e8c0dd2038a2839fe6bd1c4b2b9/YoutubeBot/docs/img/enable_annotation_processing_intellij.png -------------------------------------------------------------------------------- /YoutubeBot/docs/img/preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xatkit-bot-platform/xatkit-examples/12d71c838f0d1e8c0dd2038a2839fe6bd1c4b2b9/YoutubeBot/docs/img/preview.gif -------------------------------------------------------------------------------- /YoutubeBot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.xatkit 8 | xatkit-bot-youtube 9 | 1.0.0-SNAPSHOT 10 | 11 | jar 12 | 13 | 14 | 1.8 15 | 1.8 16 | UTF-8 17 | 3.1.0 18 | 3.2.0 19 | 20 | 4.12 21 | 3.14.0 22 | 3.3.3 23 | 1.18.12 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | com.xatkit 32 | core 33 | 5.0.0-SNAPSHOT 34 | 35 | 36 | 37 | com.xatkit 38 | chat-platform 39 | 3.0.1-SNAPSHOT 40 | 41 | 42 | 43 | com.xatkit 44 | react-platform 45 | 4.0.1-SNAPSHOT 46 | 47 | 48 | 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | 54 | 55 | 56 | 57 | 58 | junit 59 | junit 60 | 61 | 62 | 63 | org.assertj 64 | assertj-core 65 | 66 | 67 | 68 | org.mockito 69 | mockito-core 70 | 71 | 72 | 73 | 74 | com.google.api-client 75 | google-api-client 76 | 1.31.1 77 | 78 | 79 | 80 | 81 | com.google.apis 82 | google-api-services-youtube 83 | v3-rev222-1.25.0 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | org.projectlombok 95 | lombok 96 | ${lombok.version} 97 | provided 98 | 99 | 100 | 101 | 102 | 103 | junit 104 | junit 105 | ${junit.version} 106 | test 107 | 108 | 109 | 110 | org.assertj 111 | assertj-core 112 | test 113 | ${assertj.version} 114 | 115 | 116 | 117 | org.mockito 118 | mockito-core 119 | ${mockito-version} 120 | test 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | org.apache.maven.plugins 132 | maven-assembly-plugin 133 | ${maven-assembly-plugin.version} 134 | 135 | 136 | package 137 | 138 | single 139 | 140 | 141 | 142 | 143 | 144 | jar-with-dependencies 145 | 146 | 147 | 148 | com.xatkit.example.YoutubeBot 149 | 150 | 151 | youtube-bot 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | org.apache.maven.plugins 161 | maven-assembly-plugin 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /YoutubeBot/src/main/java/com/xatkit/example/YoutubeAPI.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; 4 | import com.google.api.client.googleapis.json.GoogleJsonResponseException; 5 | import com.google.api.client.http.javanet.NetHttpTransport; 6 | import com.google.api.client.json.JsonFactory; 7 | import com.google.api.client.json.jackson2.JacksonFactory; 8 | 9 | import com.google.api.services.youtube.YouTube; 10 | import com.google.api.services.youtube.model.SearchListResponse; 11 | 12 | import java.io.*; 13 | import java.security.GeneralSecurityException; 14 | 15 | public class YoutubeAPI { 16 | 17 | private static final String DEVELOPER_KEY = "YOUR DEVELOPER KEY"; 18 | private static final String APPLICATION_NAME = "YOUR APP NAME"; 19 | private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); 20 | 21 | /** 22 | * Build and return an authorized API client service. 23 | * 24 | * @return an authorized API client service 25 | * @throws GeneralSecurityException, IOException 26 | */ 27 | public static YouTube getService() throws GeneralSecurityException, IOException { 28 | final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); 29 | return new YouTube.Builder(httpTransport, JSON_FACTORY, null) 30 | .setApplicationName(APPLICATION_NAME) 31 | .build(); 32 | } 33 | 34 | /** 35 | * Call function to create API service object. Define and 36 | * execute API request. 37 | * 38 | * @return API response. 39 | * @throws GeneralSecurityException, IOException, GoogleJsonResponseException 40 | */ 41 | public static SearchListResponse getSearchListResponse(YouTube youtubeService, String keyword, Long num) 42 | throws GeneralSecurityException, IOException, GoogleJsonResponseException { 43 | YouTube.Search.List request = youtubeService.search() 44 | .list("snippet"); 45 | SearchListResponse response = request.setKey(DEVELOPER_KEY) 46 | .setMaxResults(num) 47 | .setQ(keyword) 48 | .setType("video") 49 | .execute(); 50 | return response; 51 | } 52 | } -------------------------------------------------------------------------------- /YoutubeBot/src/main/java/com/xatkit/example/YoutubeBot.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example; 2 | 3 | import com.google.api.services.youtube.YouTube; 4 | import com.xatkit.core.XatkitBot; 5 | import com.xatkit.example.utils.Video; 6 | import com.xatkit.execution.StateContext; 7 | import com.xatkit.plugins.react.platform.ReactPlatform; 8 | import com.xatkit.plugins.react.platform.io.ReactEventProvider; 9 | import com.xatkit.plugins.react.platform.io.ReactIntentProvider; 10 | import lombok.val; 11 | import org.apache.commons.configuration2.BaseConfiguration; 12 | import org.apache.commons.configuration2.Configuration; 13 | 14 | import java.io.IOException; 15 | import java.security.GeneralSecurityException; 16 | 17 | import static com.xatkit.dsl.DSL.any; 18 | import static com.xatkit.dsl.DSL.integer; 19 | import static com.xatkit.dsl.DSL.eventIs; 20 | import static com.xatkit.dsl.DSL.fallbackState; 21 | import static com.xatkit.dsl.DSL.intent; 22 | import static com.xatkit.dsl.DSL.intentIs; 23 | import static com.xatkit.dsl.DSL.model; 24 | import static com.xatkit.dsl.DSL.state; 25 | import static com.xatkit.example.YoutubeAPI.getSearchListResponse; 26 | import static com.xatkit.example.YoutubeAPI.getService; 27 | import static com.xatkit.example.utils.ResponseParser.getData; 28 | 29 | /** 30 | * This is an example bot which can search Youtube videos using a keyword provided by the user, designed with Xatkit. 31 | *

32 | * You can check our wiki 33 | * to learn more about bot creation, supported platforms, and advanced usage. 34 | */ 35 | public class YoutubeBot { 36 | 37 | private static void replyYoutubeBot(StateContext context, ReactPlatform reactPlatform, String response, String keyword) { 38 | Video[] data = getData(response); 39 | String msg = "I searched \"" + keyword + "\" and I found these videos for you...\n"; 40 | reactPlatform.reply(context, msg); 41 | 42 | for (Video video : data) { 43 | reactPlatform.replyLinkSnippet(context, video.getVideoTitle(), video.getVideoURL(), video.getThumbnailURL()); 44 | } 45 | } 46 | 47 | public static void main(String[] args) 48 | throws GeneralSecurityException, IOException { 49 | 50 | val search = intent("Search") 51 | .trainingSentence("Search KEYWORD") 52 | .trainingSentence("Search NUM videos of KEYWORD") 53 | .trainingSentence("Search NUM videos about KEYWORD") 54 | .trainingSentence("Give me KEYWORD") 55 | .trainingSentence("Give me NUM videos of KEYWORD") 56 | .trainingSentence("Give me NUM videos about KEYWORD") 57 | .trainingSentence("Search KEYWORD and give me NUM videos") 58 | .parameter("keyword").fromFragment("KEYWORD").entity(any()) 59 | .parameter("num").fromFragment("NUM").entity(integer()); 60 | 61 | YouTube youtubeService = getService(); 62 | ReactPlatform reactPlatform = new ReactPlatform(); 63 | ReactEventProvider reactEventProvider = new ReactEventProvider(reactPlatform); 64 | ReactIntentProvider reactIntentProvider = new ReactIntentProvider(reactPlatform); 65 | 66 | val init = state("Init"); 67 | val awaitingInput = state("AwaitingInput"); 68 | val handleWelcome = state("HandleWelcome"); 69 | val handleSearch = state("HandleSearch"); 70 | 71 | init 72 | .next() 73 | .when(eventIs(ReactEventProvider.ClientReady)).moveTo(handleWelcome); 74 | 75 | awaitingInput 76 | .next() 77 | .when(intentIs(search)).moveTo(handleSearch); 78 | 79 | handleWelcome 80 | .body(context -> reactPlatform.reply(context, 81 | "Hi, I am here to search Youtube videos for you! "+ 82 | "You can ask me to search videos about whatever you want. "+ 83 | "Feel free to specify the number of videos you want me to search.")) 84 | .next() 85 | .moveTo(awaitingInput); 86 | 87 | handleSearch 88 | .body(context -> { 89 | String response = null; 90 | String keyword = (String) context.getIntent().getValue("keyword"); 91 | String num_string = (String) context.getIntent().getValue("num"); 92 | long num; 93 | if (num_string.equals("")) num = 3L; 94 | else num = Long.parseLong(num_string); 95 | try { 96 | response = getSearchListResponse(youtubeService, keyword, num).toString(); 97 | } catch (GeneralSecurityException | IOException e) { 98 | e.printStackTrace(); 99 | } 100 | replyYoutubeBot(context, reactPlatform, response, keyword); 101 | }) 102 | .next() 103 | .moveTo(awaitingInput); 104 | 105 | val defaultFallback = fallbackState() 106 | .body(context -> reactPlatform.reply(context, "Sorry, I didn't get it")); 107 | 108 | val botModel = model() 109 | .usePlatform(reactPlatform) 110 | .listenTo(reactEventProvider) 111 | .listenTo(reactIntentProvider) 112 | .initState(init) 113 | .defaultFallbackState(defaultFallback); 114 | 115 | Configuration botConfiguration = new BaseConfiguration(); 116 | 117 | botConfiguration.setProperty("xatkit.dialogflow.projectId", "YOUR PROJECT ID"); 118 | botConfiguration.setProperty("xatkit.dialogflow.credentials.path", "PATH TO YOUR DIALOGFLOW CREDENTIALS"); 119 | botConfiguration.setProperty("xatkit.dialogflow.language", "en-Us"); 120 | botConfiguration.setProperty("xatkit.dialogflow.clean_on_startup", true); 121 | 122 | XatkitBot xatkitBot = new XatkitBot(botModel, botConfiguration); 123 | xatkitBot.run(); 124 | /* 125 | * The bot is now started, you can check http://localhost:5000/admin to test it. 126 | * The logs of the bot are stored in the logs folder at the root of this project. 127 | */ 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /YoutubeBot/src/main/java/com/xatkit/example/utils/ResponseParser.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example.utils; 2 | 3 | import org.json.JSONArray; 4 | import org.json.JSONObject; 5 | 6 | public class ResponseParser { 7 | 8 | public static Video[] getData(String response) { 9 | 10 | JSONObject obj = new JSONObject(response); 11 | JSONArray items = obj.getJSONArray("items"); 12 | Video[] videos = new Video[items.length()]; 13 | for (int i = 0; i < items.length(); ++i) { 14 | videos[i] = getVideoData(items.getJSONObject(i)); 15 | } 16 | return videos; 17 | } 18 | 19 | private static Video getVideoData(JSONObject item) { 20 | String videoId = item.getJSONObject("id").get("videoId").toString(); 21 | String videoTitle = item.getJSONObject("snippet").get("title").toString(); 22 | String publishTime = item.getJSONObject("snippet").get("publishTime").toString(); 23 | String channelTitle = item.getJSONObject("snippet").get("channelTitle").toString(); 24 | String channelId = item.getJSONObject("snippet").get("channelId").toString(); 25 | String thumbnail = item.getJSONObject("snippet").getJSONObject("thumbnails").getJSONObject("high").get("url").toString(); 26 | 27 | return new Video(videoId, videoTitle, channelId, channelTitle, publishTime, thumbnail); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /YoutubeBot/src/main/java/com/xatkit/example/utils/Video.java: -------------------------------------------------------------------------------- 1 | package com.xatkit.example.utils; 2 | 3 | public class Video { 4 | 5 | private String videoId; 6 | private String videoTitle; 7 | private String channelId; 8 | private String channelTitle; 9 | private String publishTime; 10 | private String videoURL; 11 | private String channelURL; 12 | private String thumbnailURL; 13 | 14 | 15 | 16 | Video(String vId, String vT, String cId, String cT, String pt, String th) { 17 | videoId = vId; 18 | videoTitle = vT; 19 | channelId = cId; 20 | channelTitle = cT; 21 | publishTime = pt; 22 | videoURL = "https://www.youtube.com/watch?v=" + videoId; 23 | channelURL = "https://www.youtube.com/channel/" + channelId; 24 | thumbnailURL = th; 25 | } 26 | 27 | public String getVideoId() { 28 | return videoId; 29 | } 30 | 31 | public void setVideoId(String videoId) { 32 | this.videoId = videoId; 33 | } 34 | 35 | public String getVideoTitle() { 36 | return videoTitle; 37 | } 38 | 39 | public void setVideoTitle(String videoTitle) { 40 | this.videoTitle = videoTitle; 41 | } 42 | 43 | public String getChannelId() { 44 | return channelId; 45 | } 46 | 47 | public void setChannelId(String channelId) { 48 | this.channelId = channelId; 49 | } 50 | 51 | public String getChannelTitle() { 52 | return channelTitle; 53 | } 54 | 55 | public void setChannelTitle(String channelTitle) { 56 | this.channelTitle = channelTitle; 57 | } 58 | 59 | public String getPublishTime() { 60 | return publishTime; 61 | } 62 | 63 | public void setPublishTime(String publishTime) { 64 | this.publishTime = publishTime; 65 | } 66 | 67 | public String getVideoURL() { 68 | return videoURL; 69 | } 70 | 71 | public void setVideoURL(String videoURL) { 72 | this.videoURL = videoURL; 73 | } 74 | 75 | public String getChannelURL() { 76 | return channelURL; 77 | } 78 | 79 | public void setChannelURL(String channelURL) { 80 | this.channelURL = channelURL; 81 | } 82 | 83 | public String getThumbnailURL() { 84 | return thumbnailURL; 85 | } 86 | 87 | public void setThumbnailURL(String thumbnailURL) { 88 | this.thumbnailURL = thumbnailURL; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /community/README.md: -------------------------------------------------------------------------------- 1 | # Community Bots 2 | 3 | The bots in this directory are contributed by the community, and are not maintained by us. They can be out of sync with the latest version of Xatkit. If this is the case you can open an issue to ask for help. -------------------------------------------------------------------------------- /community/SlackTrelloBot/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /community/SlackTrelloBot/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | SlackTrelloBot 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jdt.core.javanature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.xtext.ui.shared.xtextNature 33 | 34 | 35 | -------------------------------------------------------------------------------- /community/SlackTrelloBot/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Slack Trello Bot 4 | Bundle-SymbolicName: com.xatkit.examples.slacktrellobot 5 | Bundle-Version: 1.0.0.qualifier 6 | Require-Bundle: com.xatkit.metamodels-utils;bundle-version="3.0.0", 7 | org.eclipse.xtext.xbase.lib;bundle-version="2.15.0" 8 | Bundle-Vendor: SOM Research Lab 9 | -------------------------------------------------------------------------------- /community/SlackTrelloBot/README.md: -------------------------------------------------------------------------------- 1 | # SlackTrelloBot Example 2 | An example bot using the [SlackPlatform](https://github.com/xatkit-bot-platform/xatkit-slack-platform) and the [ZapierPlatform](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Xatkit-Zapier-Platform) to create Trello cards from Slack commands. 3 | 4 | ## Installation 5 | 6 | ### Setup Slack 7 | 8 | The SlackTrelloBot needs to be deployed on Slack. You can check [this article](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Deploying-on-Slack) to create a Slack app for Xatkit, and set its authentication token in `SlackTrelloBot.properties`: 9 | 10 | ```properties 11 | xatkit.slack.token = 12 | ``` 13 | 14 | *Xatkit Tip: Bots in Slack channels* 15 | 16 | > If you want to test your bot in a given channel **do not forget to invite the bot to this channel**, otherwise it won't be able to receive your messages and send replies 17 | 18 | ### Setup Zapier 19 | 20 | This bot is based on the Zapier integration with Trello. We need to create a new *Zap* that will create our Trello card on behalf of Xatkit. 21 | 22 | Open the [Zapier dashboard](https://zapier.com/app/dashboard) and click on `Make a Zap!` 23 | 24 | In the `When this happens` window select `Webhook by Zapier`, and select `Catch Hook` from the `Choose Trigger Event` dropdown menu. This allows to trigger your Zap from a REST request. 25 | 26 | ![Create a Zapier Webhook](https://raw.githubusercontent.com/wiki/xatkit-bot-platform/xatkit-releases/img/zapier/webhook-configuration2.png) 27 | 28 | Click on `Continue`, and note the content of the `Custom Webhook URL` field, we will reuse it later to configure Xatkit, then click again on `Continue`. The last step allows to find some data from example REST requests, we don't need it in this example, so you can simply click on `Skip Test`. 29 | 30 | ![Skip Find Data](https://raw.githubusercontent.com/wiki/xatkit-bot-platform/xatkit-releases/img/zapier/webhook-configuration3.png) 31 | 32 | We now need to configure the action to perform once the Zap is triggered. In the `Do this ...` window select `Trello`, and select `Create Card` from the `Choose Action Event` dropdown menu. Zapier will then ask you to login with your Trello account in order to load your boards. 33 | 34 | 35 | 36 | ![Create a Trello Action](https://raw.githubusercontent.com/wiki/xatkit-bot-platform/xatkit-releases/img/zapier/webhook-configuration4.png) 37 | 38 | 39 | 40 | Navigate to the `Customize Card` tab, and fill the `Board` and `List` fields with the Trello board and list to add cards in. Fill the `Name` field with the following content: `{{name}}`, this is the Zapier way to specify that we want to access the `name` value from the received JSON payload (this value is set in *ZapierPlatform.PostAction* action in the execution model). You can leave the default values for the other fields. Once this is done you should have an action similar to the one shown below (note that Zapier formatted our `{{name}}` into a user-friendly representation): 41 | 42 | ![Customize Card Example](https://raw.githubusercontent.com/wiki/xatkit-bot-platform/xatkit-releases/img/zapier/webhook-configuration5.png) 43 | 44 | 45 | 46 | Click on continue, and skip the *Send Data* test proposed at the end of the process. 47 | 48 | Congratulation, you have just created your Zap! Make sure that your Zap is turned on by checking it in your [dashboard](https://zapier.com/app/zaps). 49 | 50 | We now need to tell Xatkit to use your Zap. To do it update the `SlackTrelloBot.properties` file to set the Zapier endpoint url the bot should use: use the `Custom Webhook URL` value noted previously (you can retrieve it by editing your Zap in the dashboard ;) ) 51 | 52 | ```properties 53 | zapier.endpoint = 54 | ``` 55 | 56 | *Xatkit Tip: Getting help with Zapier* 57 | 58 | > If you experience any issue with Zapier you can take a look at the Zapier [documentation on webhooks](https://zapier.com/apps/webhook/help). 59 | 60 | ### Optional Step: setup DialogFlow 61 | 62 | The SlackTrelloBot example relies on Xatkit RegExp intent provider, that performs exact matching of user inputs to extract intents. If you want to use a more powerful intent provider such as DialogFlow you can take a look at [this article](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Integrating-DialogFlow). 63 | 64 | ## Run your bot 65 | 66 | Start your bot with the following command: 67 | 68 | ```bash 69 | cd $XATKIT/bin 70 | ./start-xatkit-windows.sh 71 | ``` 72 | 73 | If you don't have a local installation of Xatkit you can check [this article](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Installation) to install and setup Xatkit on your machine. 74 | 75 | ## Test your bot 76 | 77 | Open a direct message channel with the deployed bot and write the following message: `Create a card Test`, then check that a new card named `Test` has been created on the board and list specified in your Zap! 78 | 79 | You can also invite your bot to a Slack channel and write the following message: `@ Create a card Test`, where `` is the name of your bot. Note that the bot will not reply in a channel if you haven't explicitly mentioned it (this is specified by the `xatkit.slack.listen_mentions_on_group_channels = true` property in `SlackTrelloBot.properties`). 80 | 81 | -------------------------------------------------------------------------------- /community/SlackTrelloBot/SlackTrelloBot.properties: -------------------------------------------------------------------------------- 1 | # Execution model 2 | xatkit.execution.model = src/SlackTrelloBot.execution 3 | xatkit.libraries.custom.SlackTrelloBotLib = src/SlackTrelloBot.intent 4 | 5 | # Slack configuration 6 | xatkit.slack.token = 7 | # Only listen to explicit mentions in group channels (we don't want to trigger intents everytime a message is sent to the channel) 8 | xatkit.slack.listen_mentions_on_group_channels = true 9 | 10 | # Zapier configuration 11 | zapier.endpoint = 12 | 13 | -------------------------------------------------------------------------------- /community/SlackTrelloBot/src/SlackTrelloBot.execution: -------------------------------------------------------------------------------- 1 | import library "SlackTrelloBot/src/SlackTrelloBot.intent" as SlackTrelloBotLib 2 | import library "CoreLibrary" 3 | import platform "ZapierPlatform" 4 | import platform "SlackPlatform" 5 | 6 | use provider SlackPlatform.SlackIntentProvider 7 | 8 | Init { 9 | Next { 10 | intent == Presentation --> HandlePresentation 11 | intent == NewCard --> HandleNewCard 12 | } 13 | } 14 | 15 | HandlePresentation { 16 | Body { 17 | SlackPlatform.Reply("Hi! I am the Trello bot, you can ping me to store some information on Trello for you. I am configured to create cards here: Xatkit/Slack Triage\n 18 | To ask me to remember something use the following pattern: `@XatkitTrello create card `") 19 | } 20 | Next { 21 | _ --> Init 22 | } 23 | } 24 | 25 | HandleNewCard { 26 | Body { 27 | ZapierPlatform.PostAction(config.get("zapier.endpoint") as String, "{ 'name' : '" + context.get("Card").get("name") + "' }") 28 | SlackPlatform.Reply("Done!") 29 | } 30 | Next { 31 | _ --> Init 32 | } 33 | } 34 | 35 | Default_Fallback { 36 | Body { 37 | SlackPlatform.Reply("Sorry, I didn't get it") 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /community/SlackTrelloBot/src/SlackTrelloBot.intent: -------------------------------------------------------------------------------- 1 | Library SlackTrelloBotLibrary 2 | 3 | intent Presentation { 4 | inputs { 5 | "Can you introduce yourself?" 6 | "Present yourself" 7 | "Explain what you do" 8 | "Why are you here?" 9 | } 10 | } 11 | 12 | intent NewCard { 13 | inputs { 14 | "Create a card CardName" 15 | "Create a card named CardName" 16 | "Create a card with title CardName" 17 | "Create a card called CardName" 18 | "Create card CardName" 19 | "New card CardName" 20 | "New card with title CardName" 21 | "Add card CardName" 22 | "Add a card with title CardName" 23 | } 24 | creates context Card { 25 | sets parameter name from fragment "CardName" (entity any) 26 | } 27 | } -------------------------------------------------------------------------------- /community/Twitter/CanYouTweet/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /community/Twitter/CanYouTweet/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | CanYouTweet 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jdt.core.javanature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.xtext.ui.shared.xtextNature 33 | 34 | 35 | -------------------------------------------------------------------------------- /community/Twitter/CanYouTweet/CanYouTweet.properties: -------------------------------------------------------------------------------- 1 | # Execution file containing the logic of the bot 2 | xatkit.execution.model = src/CanYouTweet.execution 3 | 4 | # Resolve alias imports in Execution model 5 | xatkit.libraries.custom.CanYouTweetLib = src/CanYouTweet.intent 6 | 7 | # Slack Credentials (see https://github.com/xatkit-bot-platform/xatkit/wiki/Deploying-chatbots) 8 | xatkit.slack.token = 9 | 10 | # Twitter configuration 11 | xatkit.twitter.consumerKey = 12 | xatkit.twitter.consumerSecret = 13 | xatkit.twitter.accessToken = 14 | xatkit.twitter.accessSecretToken = 15 | 16 | # DialogFlow configuration (remove if not planning to use DialogFlow) 17 | xatkit.dialogflow.projectId = 18 | xatkit.dialogflow.credentials.path = 19 | xatkit.dialogflow.language = en-US 20 | xatkit.dialogflow.clean_on_startup = true -------------------------------------------------------------------------------- /community/Twitter/CanYouTweet/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: CanYouTweet 4 | Bundle-SymbolicName: com.xatkit.examples.canyoutweet 5 | Bundle-Version: 1.0.0.qualifier 6 | Require-Bundle: com.xatkit.metamodels-utils;bundle-version="3.0.0", 7 | org.eclipse.xtext.xbase.lib;bundle-version="2.15.0" 8 | Bundle-Vendor: SOM Research Lab 9 | -------------------------------------------------------------------------------- /community/Twitter/CanYouTweet/README.md: -------------------------------------------------------------------------------- 1 | CanYouTweet Example 2 | ===== 3 | 4 | An example bot using the [TwitterPlatform](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Xatkit-Twitter-Platform) and [SlackPlatform](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Xatkit-Slack-Platform) to look for tweets, send direct messages, and tweet on behalf of a user. 5 | 6 | ## Installation 7 | 8 | 9 | ### Build the Twitter platform 10 | 11 | This bot relies on the TwitterPlatform that is not yet released. To run it you need to have a local installation of the [XDK](https://github.com/xatkit-bot-platform/xatkit-dev) and perform the following commands: 12 | 13 | ```bash 14 | cd $XATKIT_DEV 15 | cd src/platforms 16 | git clone https://github.com/xatkit-bot-platform/xatkit-twitter-platform.git 17 | cd $XATKIT_DEV 18 | ./build.sh --platform=xatkit-twitter-platform --product 19 | ``` 20 | 21 | This will build a local version of the Twitter platform that can be imported from execution models. 22 | 23 | ### Setup Slack 24 | 25 | The GithubBot needs to be deployed on Slack. You can check [this article](https://github.com/xatkit-bot-platform/xatkit-runtime/wiki/Deploying-chatbots#create-a-slack-app) to create a Slack app for Xatkit, and set its authentication token in `GithubBot.properties`: 26 | 27 | ```properties 28 | xatkit.slack.token = 29 | ``` 30 | 31 | ### Setup Twitter 32 | 33 | In order to connect the bot to the Twitter API you need to provide a set of credentials in the `.properties` file. You can check [this article](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Xatkit-Twitter-Platform#options) to see how to setup a Twitter App for Xatkit. 34 | 35 | ### Optional Step: setup DialogFlow 36 | 37 | The GithubBot example relies on Xatkit RegExp intent provider, that performs exact matching of user inputs to extract intents. If you want to use a more powerful intent provider such as DialogFlow you can take a look at [this article](https://github.com/xatkit-bot-platform/xatkit-runtime/wiki/Deploying-chatbots#create-a-dialogflow-project). 38 | 39 | ## Run your bot 40 | 41 | Start your bot with the following commands: 42 | 43 | ```bash 44 | cd $XATKIT/bin 45 | ./start-xatkit-windows.sh 46 | ``` 47 | 48 | ## Test your bot 49 | 50 | You can test your bot by opening a direct message channel with it on Slack and ask it the following questions: 51 | - `Can you post ` 52 | - `Can you send a DM to ` 53 | - `Can you show me my messages?` 54 | - `Can you look for ?` 55 | 56 | **Note**: if you didn't setup DialogFlow the bot will rely on the default regular expression recognition service, that only accepts fragments without spaces for `` (e.g. "Can you look for football" will work, while "Can you look for football matches" won't). 57 | 58 | You can find below an example of the bot in action: 59 | 60 | ![Twitter Bot in action](https://raw.githubusercontent.com/wiki/xatkit-bot-platform/xatkit-releases/img/twitter-bot-example.png) 61 | -------------------------------------------------------------------------------- /community/Twitter/CanYouTweet/lib/xatkit-twitter-runtime-1.0.1-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xatkit-bot-platform/xatkit-examples/12d71c838f0d1e8c0dd2038a2839fe6bd1c4b2b9/community/Twitter/CanYouTweet/lib/xatkit-twitter-runtime-1.0.1-SNAPSHOT.jar -------------------------------------------------------------------------------- /community/Twitter/CanYouTweet/src/CanYouTweet.execution: -------------------------------------------------------------------------------- 1 | import library "CanYouTweet/src/CanYouTweet.intent" as CanYouTweetLib 2 | import library "CoreLibrary" 3 | import platform "SlackPlatform" 4 | import platform "TwitterPlatform" 5 | import library "CoreLibrary" 6 | 7 | use provider SlackPlatform.SlackIntentProvider 8 | 9 | on intent Greetings do 10 | SlackPlatform.Reply("Hi, I can help you interact with twitter!\nYou can start with something like `Can you post ?") 11 | 12 | on intent Help do 13 | SlackPlatform.Reply('You can try "search for "') 14 | 15 | //----Twitter specific---- 16 | on intent PostTweet do 17 | val content = context.get("Twitter").get("content") as String 18 | if(content != ""){ 19 | val result = TwitterPlatform.PostAtweet(content) 20 | 21 | if(result == 0){ 22 | SlackPlatform.Reply('I just tweeted: _' + content + '_ for you.') 23 | }else{ 24 | SlackPlatform.Reply("I couldn't tweet that for you right now.") 25 | } 26 | }else{ 27 | SlackPlatform.Reply("I'm not going to post an empty tweet, look somewhere else") 28 | } 29 | 30 | on intent SearchTweets do 31 | val contentQuery = context.get("Twitter").get("query") as String 32 | if(contentQuery != ""){ 33 | val result = TwitterPlatform.LookForTweets(contentQuery) 34 | 35 | if(result == "1"){ 36 | SlackPlatform.Reply("I couldn't do that search") 37 | }else{ 38 | if(result == "0"){ 39 | SlackPlatform.Reply("No results for: _" + contentQuery + "_") 40 | }else{ 41 | SlackPlatform.ReplyAttachmentsMessage(result as java.util.List) 42 | } 43 | } 44 | }else{ 45 | SlackPlatform.Reply("I can't search for that") 46 | } 47 | 48 | on intent SendDM do 49 | if(context.get("Twitter").get("user") != ""){ 50 | SlackPlatform.Reply("Ok, so you want to send a DM to *@" + context.get("Twitter").get("user") + "*") 51 | SlackPlatform.Reply('Write "DM content:" and then add what you want to say to him/her in double quotes.') 52 | }else{ 53 | SlackPlatform.Reply("I don't know anyone by that name") 54 | } 55 | 56 | on intent SpecifyDM do 57 | val DMcontent = context.get("Twitter").get("text") as String 58 | if(DMcontent != ""){ 59 | val result = TwitterPlatform.SendDM(context.get("Twitter").get("user") as String, DMcontent) 60 | if(result == 0){ 61 | SlackPlatform.Reply('Message Sent! :smile:') 62 | }else{ 63 | SlackPlatform.Reply("I couldn't send it :upside_down_face:") 64 | } 65 | }else{ 66 | SlackPlatform.Reply("I'm not going to send that") 67 | } 68 | 69 | on intent ReceiveDM do 70 | val result = TwitterPlatform.ReceiveDM 71 | if (result == "1"){ 72 | SlackPlatform.Reply("I couldn't retrieve any message, try again later. :upside_down_face:") 73 | }else{ 74 | if(result == "0"){ 75 | SlackPlatform.Reply("There are no messages...") 76 | }else{ 77 | SlackPlatform.ReplyAttachmentsMessage(result as java.util.List) 78 | } 79 | } 80 | 81 | on intent GetTrends do 82 | var Object result = null; 83 | var noResultsMessage = ""; 84 | if(context.get("Twitter").get("woeid") != ""){ 85 | result = TwitterPlatform.GetTrends(Integer.parseInt(context.get("Twitter").get("woeid") as String)) 86 | noResultsMessage = "No trending topics where found for the WOEID: " + context.get("Twitter").get("woeid") 87 | } 88 | else { 89 | if (context.get("Twitter").get("locationName") != ""){ 90 | result = TwitterPlatform.GetTrends(context.get("Twitter").get("locationName") as String) 91 | noResultsMessage = "No trending topics where found for the location with name: " + context.get("Twitter").get("locationName") 92 | }else { 93 | result = TwitterPlatform.GetTrends() 94 | noResultsMessage = "No trending topics where found worldwide" 95 | } 96 | } 97 | if (result == "1"){ 98 | SlackPlatform.Reply("An error occurred while trying to retrieve the ternding topics, try again later. :upside_down_face:") 99 | }else{ 100 | if(result == "0"){ 101 | SlackPlatform.Reply(noResultsMessage) 102 | }else{ 103 | SlackPlatform.ReplyAttachmentsMessage(result as java.util.List) 104 | } 105 | } 106 | 107 | on intent Default_Fallback_Intent do 108 | SlackPlatform.Reply("Sorry I'll have to check that on my dictionary and get back to you later :(") 109 | -------------------------------------------------------------------------------- /community/Twitter/CanYouTweet/src/CanYouTweet.intent: -------------------------------------------------------------------------------- 1 | Library CanYouTweetLib 2 | 3 | intent Greetings { 4 | inputs { 5 | "Hi" 6 | "Hello" 7 | "Greetings" 8 | "Morning" 9 | "Afternoon" 10 | "Evening" 11 | } 12 | } 13 | 14 | intent PostTweet{ 15 | inputs{ 16 | 'can you tweet CONTENT?' 17 | 'can you post CONTENT?' 18 | "tweet CONTENT" 19 | "post CONTENT" 20 | "post tweet CONTENT" 21 | "post this tweet: CONTENT" 22 | "please tweet CONTENT" 23 | "please post CONTENT" 24 | "just tweet CONTENT" 25 | "just post CONTENT" 26 | } 27 | creates context Twitter { 28 | sets parameter content from fragment "CONTENT" (entity any) 29 | } 30 | } 31 | 32 | intent SearchTweets{ 33 | inputs{ 34 | "can you show tweets about TWEETS" 35 | "can you search for TWEETS" 36 | "can you search tweets with TWEETS" 37 | "can you look for TWEETS" 38 | "can you find TWEETS" 39 | 40 | "show tweets of TWEETS" 41 | "show tweets about TWEETS" 42 | 'search for TWEETS' 43 | 'search for tweets TWEETS' 44 | 'search for tweets of TWEETS' 45 | "search tweets with TWEETS" 46 | 'search tweets about TWEETS' 47 | 'look for TWEETS' 48 | "look for tweets TWEETS" 49 | "find TWEETS" 50 | "find tweets TWEETS" 51 | } 52 | creates context Twitter { 53 | sets parameter query from fragment "TWEETS" (entity any) 54 | } 55 | } 56 | 57 | intent SendDM { 58 | inputs { 59 | "can you send dm to USER" 60 | "can you send message to USER" 61 | "can you send text to USER" 62 | 63 | "dm to USER" 64 | "message to USER" 65 | "text to USER" 66 | "send dm to USER" 67 | "send message to USER" 68 | "send text to USER" 69 | "please send dm to USER" 70 | "please send message to USER" 71 | "please text to USER" 72 | } 73 | creates context Twitter { 74 | sets parameter user from fragment "USER" (entity any) 75 | } 76 | } 77 | 78 | intent SpecifyDM follows SendDM { 79 | inputs { 80 | 'DM content: "(Twitter:text=@any)"' 81 | } 82 | } 83 | 84 | intent ReceiveDM { 85 | inputs{ 86 | "can you show me my messages" 87 | "can you show me messages" 88 | "can you show me all messages" 89 | 90 | "show me my messages" 91 | "show me messages" 92 | "show me all messages" 93 | "who wrote me" 94 | "show messages" 95 | "show dm" 96 | "do I have messages" 97 | "are there messages" 98 | } 99 | } 100 | 101 | intent GetTrends { 102 | inputs { 103 | "get trends" 104 | "show trends" 105 | "get trending topics" 106 | "show trending topics" 107 | "get trends from 123" 108 | "show trends from 123" 109 | "get trending topics from 123" 110 | "show trending topics from 123" 111 | "get trends from Uruguay" 112 | "show trends from Uruguay" 113 | "get trending topics from Uruguay" 114 | "show trending topics from Uruguay" 115 | } 116 | 117 | creates context Twitter { 118 | sets parameter woeid from fragment "123" (entity integer) 119 | sets parameter locationName from fragment "Uruguay" (entity country) 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /outdated/GithubBot/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /outdated/GithubBot/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | GithubBot 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jdt.core.javanature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.xtext.ui.shared.xtextNature 33 | 34 | 35 | -------------------------------------------------------------------------------- /outdated/GithubBot/GithubBot.properties: -------------------------------------------------------------------------------- 1 | # Execution model 2 | xatkit.execution.model = src/GithubBot.execution 3 | xatkit.libraries.custom.GithubBotLib = src/GithubBot.intent 4 | 5 | # Slack configuration 6 | xatkit.slack.token = 7 | # You can customize the channel the bot will use with the property below 8 | # /!\ Do not forget to invite the bot to the specified channel, otherwise it won't be able to reply to your messages 9 | slack.channel = 10 | 11 | # Github configuration 12 | xatkit.github.oauth.token = 13 | # Set the repository name and username to use to test the bot 14 | # Github repositories are specified with the following pattern: username/name 15 | # (e.g. xatkit-bot-platform/xatkit-runtime corresponds to the username xatkit-bot-platform and the repository name xatkit-runtime) 16 | # Note that you probably don't have full permissions on the specified example repository, meaning that some actions cannot be computed. 17 | # To fully setup the bot you can create your own test repository following the README here https://github.com/xatkit-bot-platform/xatkit-examples/blob/master/GithubBot/README.md 18 | github.repository.username = jcabot 19 | github.repository.name = xatkit-tests 20 | 21 | 22 | # DialogFlow configuration (remove if not planning to use DialogFlow) 23 | xatkit.dialogflow.projectId = 24 | xatkit.dialogflow.credentials.path = 25 | xatkit.dialogflow.language = en-US 26 | xatkit.dialogflow.clean_on_startup = true 27 | -------------------------------------------------------------------------------- /outdated/GithubBot/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: SOM Research Lab 4 | Bundle-SymbolicName: com.xatkit.examples.githubbot 5 | Bundle-Version: 1.0.0.qualifier 6 | Require-Bundle: com.xatkit.metamodels-utils;bundle-version="3.0.0", 7 | org.eclipse.xtext.xbase.lib;bundle-version="2.15.0" 8 | -------------------------------------------------------------------------------- /outdated/GithubBot/README.md: -------------------------------------------------------------------------------- 1 | # GitHubBot Example 2 | An example bot using the [SlackPlatform](https://github.com/xatkit-bot-platform/xatkit-slack-platform) and the [GitHubPlatform](https://github.com/xatkit-bot-platform/xatkit-github-platform) to receive events from GitHub and manage opened issues from Slack. You can check the [blog article](https://livablesoftware.com/slack-chatbot-github-repositories/) to know more about this bot! 3 | 4 | ## Installation 5 | 6 | ### Setup Slack 7 | 8 | The GitHubBot needs to be deployed on Slack. You can check [this article](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Deploying-on-Slack) to create a Slack app for Xatkit, and set its authentication token in `GithubBot.properties`: 9 | 10 | ```properties 11 | xatkit.slack.token = 12 | ``` 13 | 14 | You can also set the channel used by the GithubBot to post messages (the `general` channel is used by default): 15 | 16 | ```properties 17 | slack.channel = general 18 | ``` 19 | 20 | **Do not forget to invite the bot to your channel, otherwise it won't be able to reply to you** 21 | 22 | ### Setup GitHub 23 | 24 | This bot requires GitHub credentials to receive events from the Github API and perform actions, you can navigate to [this page](https://github.com/settings/tokens) and click on **Generate new token** to create a new personal access token, give it a name, and select the **repo** scope. Copy the created access token in the `GithubBot.properties`: 25 | 26 | ```properties 27 | xatkit.github.oauth.token = 28 | ``` 29 | 30 | Finally, you'll need to set the Github repository that is managed by the GithubBot. To do so, create a new Github repository (or use an existing one) and perform the following actions: 31 | 32 | - Navigate in the **Settings** of your repository, open the **Webhooks** tab, click on **Add webhook**, and set the following informations: 33 | - **Payload URL**: https://xatkit.serveo.net/github/ 34 | - **Content type**: *application/json* 35 | - Under the **Which events would you like to trigger this webhook?** menu select Send me **everything**. 36 | - Update the `github.repository.username` and `github.repository.name` properties in `GithubBot.properties` with your repository's information. 37 | 38 | Serveo is used to forward the payload to your local port. If you're already running Xatkit in a public server just use that server URL. Instead of Serveo, you could also use ngrok. 39 | 40 | ### Optional Step: setup DialogFlow 41 | 42 | The GithubBot example relies on Xatkit RegExp intent provider, that performs exact matching of user inputs to extract intents. If you want to use a more powerful intent provider such as DialogFlow you can take a look at [this article](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Integrating-DialogFlow). 43 | 44 | ## Run your bot 45 | 46 | Open a terminal and execute this command: 47 | 48 | ```bash 49 | ssh -R xatkit.serveo.net:80:localhost:5000 serveo.net 50 | ``` 51 | 52 | This will redirect the payloads sent by Github to your localhost, allowing Xatkit to capture them and trigger events. 53 | 54 | *Xatkit Tip* 55 | > If serveo is not up you can check out [ngrok](https://ngrok.com/) or [packetriot](https://packetriot.com/) that provide similar features. 56 | 57 | Start your bot: 58 | 59 | ```bash 60 | cd $XATKIT/bin 61 | ./start-xatkit-windows.sh 62 | ``` 63 | 64 | If you don't have a local installation of Xatkit you can check [this article](https://github.com/xatkit-bot-platform/xatkit-releases/wiki/Installation) to install and setup Xatkit on your machine. 65 | 66 | ## Test your bot 67 | 68 | Open an issue in the repository you configured before. The bot should send a new message in your Slack channel you configured. You can reply to this message with the following test sentences: 69 | 70 | - Set label bug 71 | - Assign user `` (e.g. "Assign user gdaniel") 72 | 73 | Check the issue in your repository, it should now be labeled `bug`, and assigned to the user you defined. 74 | -------------------------------------------------------------------------------- /outdated/GithubBot/lib/xatkit-github-runtime-2.1.1-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xatkit-bot-platform/xatkit-examples/12d71c838f0d1e8c0dd2038a2839fe6bd1c4b2b9/outdated/GithubBot/lib/xatkit-github-runtime-2.1.1-SNAPSHOT.jar -------------------------------------------------------------------------------- /outdated/GithubBot/src/GithubBot.execution: -------------------------------------------------------------------------------- 1 | import library "GithubBot/src/GithubBot.intent" as GithubBotLib 2 | import platform "GithubPlatform" 3 | import platform "SlackPlatform" 4 | import library "CoreLibrary" 5 | 6 | use provider SlackPlatform.SlackIntentProvider 7 | use provider GithubPlatform.GithubWebhookEventProvider 8 | 9 | Init { 10 | Next { 11 | event == Issue_Opened --> HandleIssueOpened 12 | intent == GetIssue --> HandleGetIssue 13 | intent == OpenBug --> HandleOpenBug 14 | } 15 | } 16 | 17 | /* 18 | * "Developer" part: receive events when an issue is opened, and set label/assign users to it from Slack 19 | */ 20 | 21 | HandleIssueOpened { 22 | Body { 23 | val issue = GithubPlatform.GetIssue(config.get("github.repository.username") as String, config.get("github.repository.name") as String, context.get("issue").get("issue->number") as String) 24 | session.put("issue", issue) 25 | SlackPlatform.PostAttachmentsMessage("A new issue has been opened on <" + context.get("issue").get("repository->html_url") + " | " + context.get("issue").get("repository->name") +">", 26 | context.get("issue").get("issue->title") as String, 27 | (if(issue.body.empty) "No description provided" else issue.body) + "\n(<" + context.get("issue").get("issue->html_url") + " | open on Github>)", 28 | "#D21F3C", 29 | config.get("slack.channel") as String, 30 | config.get("slack.team") as String 31 | ) 32 | } 33 | Next { 34 | intent == SetLabel --> HandleSetLabel 35 | intent == AssignUser --> HandleAssignUser 36 | intent == GetIssue --> HandleGetIssue endOfPath 37 | } 38 | } 39 | 40 | HandleGetIssue { 41 | Body { 42 | val com.jcabi.github.Issue issue = GithubPlatform.GetIssue(config.get("github.repository.username") as String, config.get("github.repository.name") as String, context.get("issue").get("issueNumber") as String) 43 | session.put("issue", issue) 44 | SlackPlatform.Reply("Found issue " + issue.number()) 45 | } 46 | Next { 47 | intent == SetLabel --> HandleSetLabel 48 | intent == AssignUser --> HandleAssignUser 49 | intent == GetIssue --> HandleGetIssue endOfPath 50 | } 51 | } 52 | 53 | HandleSetLabel { 54 | Body { 55 | val issue = session.get("issue") as com.jcabi.github.Issue.Smart 56 | GithubPlatform.SetLabel(issue, context.get("issue").get("issueLabel") as String) 57 | SlackPlatform.Reply("Issue " + issue.number + " labeled " + context.get("issue").get("issueLabel")) 58 | } 59 | Next { 60 | intent == AssignUser --> HandleAssignUser 61 | intent == SetLabel --> HandleSetLabel 62 | intent == GetIssue --> HandleGetIssue endOfPath 63 | } 64 | } 65 | 66 | HandleAssignUser { 67 | Body { 68 | val issue = session.get("issue") as com.jcabi.github.Issue.Smart 69 | GithubPlatform.AssignUser(issue, context.get("issue").get("assignedUsername") as String) 70 | SlackPlatform.Reply("Issue " + issue.number + " assigned to " + context.get("issue").get("assignedUsername")) 71 | } 72 | Next { 73 | intent == SetLabel --> HandleSetLabel 74 | intent == AssignUser --> HandleAssignUser 75 | intent == GetIssue --> HandleGetIssue endOfPath 76 | } 77 | } 78 | 79 | /* 80 | * "Newcomer" part: open an issue on Github from Slack 81 | */ 82 | HandleOpenBug { 83 | Body { 84 | SlackPlatform.Reply("Can you please describe what is wrong in a few words?") 85 | } 86 | Next { 87 | intent == DescribeBug --> HandleDescribeBug 88 | } 89 | } 90 | 91 | HandleDescribeBug { 92 | Body { 93 | SlackPlatform.Reply("Can you let us know the WordPress version you're using?") 94 | } 95 | Next { 96 | intent == TellWPVersion --> HandleWPVersion 97 | } 98 | } 99 | 100 | HandleWPVersion { 101 | Body { 102 | SlackPlatform.Reply("Can you let us know the PHP version you're using?") 103 | } 104 | Next { 105 | intent == TellPHPVersion --> HandlePHPVersion 106 | } 107 | } 108 | 109 | HandlePHPVersion { 110 | Body { 111 | val newIssue = GithubPlatform.OpenIssue(config.get("github.repository.username") as String, config.get("github.repository.name") as String, context.get("bug").get("title") as String, 112 | "WP version is " + context.get("bug").get("wpversion") as String + " PHP version is " + context.get("bug").get("phpversion") as String 113 | ) 114 | GithubPlatform.SetLabel(newIssue, "bug") 115 | SlackPlatform.Reply("Thanks for your detailed info, I have opened an <" + newIssue.htmlUrl + " |issue> on Github for you") 116 | } 117 | Next { 118 | _ --> Init endOfPath 119 | } 120 | } 121 | 122 | Default_Fallback { 123 | Body { 124 | SlackPlatform.Reply("Sorry, I didn't get it") 125 | } 126 | } 127 | 128 | 129 | -------------------------------------------------------------------------------- /outdated/GithubBot/src/GithubBot.intent: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xatkit-bot-platform/xatkit-examples/12d71c838f0d1e8c0dd2038a2839fe6bd1c4b2b9/outdated/GithubBot/src/GithubBot.intent -------------------------------------------------------------------------------- /outdated/README.md: -------------------------------------------------------------------------------- 1 | # Community Bots 2 | 3 | The bots in this directory were created using previous versions of Xatkit. Kept here for illustration purposes. -------------------------------------------------------------------------------- /outdated/ReactSlackLiveChat/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /outdated/ReactSlackLiveChat/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ReactSlackLiveChat 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jdt.core.javanature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.xtext.ui.shared.xtextNature 33 | 34 | 35 | -------------------------------------------------------------------------------- /outdated/ReactSlackLiveChat/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: ReactSlackLiveChat 4 | Bundle-SymbolicName: com.xatkit.examples.reactslacklivechat 5 | Bundle-Version: 1.0.0.qualifier 6 | Require-Bundle: org.eclipse.xtext.xbase.lib;bundle-version="2.15.0", 7 | com.xatkit.metamodels-utils;bundle-version="3.0.0" 8 | Bundle-Vendor: SOM Research Lab 9 | -------------------------------------------------------------------------------- /outdated/ReactSlackLiveChat/ReactSlackLiveChat.properties: -------------------------------------------------------------------------------- 1 | # Execution model 2 | xatkit.execution.model = src/ReactSlackLiveChat.execution 3 | 4 | xatkit.libraries.custom.ReactSlackLiveChatLib = src/ReactSlackLiveChat.intent 5 | 6 | # Slack configuration 7 | xatkit.slack.token = 8 | 9 | # The Slack channel used to forward messages from the web component. 10 | slack.channel = general 11 | # The name of the user to forward unmatched intents to 12 | slack.username = username 13 | # the identifier of the workspace where the bot is installed 14 | slack.team = team 15 | 16 | # Configure the message delay (optional) 17 | # xatkit.message.delay = 500 18 | 19 | -------------------------------------------------------------------------------- /outdated/ReactSlackLiveChat/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | bin.includes = META-INF/,\ 3 | . 4 | -------------------------------------------------------------------------------- /outdated/ReactSlackLiveChat/src/ReactSlackLiveChat.execution: -------------------------------------------------------------------------------- 1 | import library "CoreLibrary" 2 | import library "ReactSlackLiveChat/src/ReactSlackLiveChat.intent" as ReactSlackLiveChatLib 3 | import platform "ReactPlatform" 4 | import platform "SlackPlatform" 5 | 6 | use provider ReactPlatform.ReactIntentProvider 7 | use provider ReactPlatform.ReactEventProvider 8 | use provider SlackPlatform.SlackIntentProvider 9 | 10 | Init { 11 | Next { 12 | event == Client_Ready --> GreetUser 13 | } 14 | } 15 | 16 | GreetUser { 17 | Body { 18 | ReactPlatform.Reply("Hi, I am a semi-autonomous bot and I'll do my best to answer your questions!") 19 | } 20 | Next { 21 | _ --> AwaitQuestion 22 | } 23 | } 24 | 25 | AwaitQuestion { 26 | Next { 27 | intent == XatkitQuestion --> HandleXatkitQuestion 28 | intent == WhoIsBehindXatkit --> HandleWhoIsBehindXatkit 29 | event == Client_Closed --> HandleClientClosed 30 | } 31 | } 32 | 33 | HandleXatkitQuestion { 34 | Body { 35 | if(intent.fromPlatform == "ReactPlatform") { 36 | ReactPlatform.Reply("What about [Xatkit](https://xatkit.com/)? It's an awesome low-code platform for bot development!") 37 | } 38 | } 39 | Next { 40 | _ --> AwaitQuestion endOfPath 41 | } 42 | } 43 | 44 | HandleWhoIsBehindXatkit { 45 | Body { 46 | if(intent.fromPlatform == "ReactPlatform") { 47 | ReactPlatform.Reply("Xatkit is developed by [gdaniel](https://github.com/gdaniel) and [jcabot](https://github.com/jcabot), take a look at their profile to know more about them!") 48 | } 49 | } 50 | Next { 51 | _ --> AwaitQuestion endOfPath 52 | } 53 | } 54 | 55 | HandleClientClosed { 56 | Body { 57 | val reactSlackMap = session.get("react-slack-map") as com.google.common.collect.BiMap 58 | if(reactSlackMap !== null) { 59 | val slackTs = reactSlackMap.remove(context.get("react").get("channel")) 60 | SlackPlatform.PostMessage("_The client has closed the connection_", config.get("slack.channel") as String, config.get("slack.team") as String, slackTs) 61 | } 62 | } 63 | Next { 64 | _ --> Init endOfPath 65 | } 66 | } 67 | 68 | Default_Fallback { 69 | Body { 70 | if(intent.fromPlatform == "ReactPlatform") { 71 | val reactChannel = context.get("chat").get("channel") as String 72 | var reactSlackMap = session.get("react-slack-map") as com.google.common.collect.BiMap 73 | if(reactSlackMap === null) { 74 | reactSlackMap = com.google.common.collect.HashBiMap.create 75 | session.put("react-slack-map", reactSlackMap) 76 | } 77 | val storedSlackTs = reactSlackMap.get(reactChannel) 78 | val userOnline = SlackPlatform.IsOnline(config.get("slack.username") as String, config.get("slack.team") as String) 79 | if(userOnline) { 80 | if(storedSlackTs === null) { 81 | ReactPlatform.Reply("Sorry I didn't get it, I forward your request to the closed human being") 82 | val slackTs = SlackPlatform.PostMessage("[" + context.get("chat").get("username") + "] " + intent.matchedInput, config.get("slack.channel") as String, config.get("slack.team") as String) as String 83 | reactSlackMap.put(reactChannel, slackTs) 84 | SlackPlatform.PostMessage("_Replies in this thread will be forwarded to the user_", config.get("slack.channel") as String, config.get("slack.team") as String, slackTs) 85 | } else { 86 | SlackPlatform.PostMessage("[" + context.get("chat").get("username") + "] " + intent.matchedInput, config.get("slack.channel") as String, config.get("slack.team") as String, storedSlackTs) 87 | } 88 | } else { 89 | ReactPlatform.Reply("Sorry, all our human beings are away for now, you can drop us an email at example@example.com") 90 | } 91 | } else if(intent.fromPlatform == "SlackPlatform") { 92 | val reactSlackMap = session.get("react-slack-map") as com.google.common.collect.BiMap 93 | if(reactSlackMap !== null) { 94 | val slackTs = context.get("slack").get("threadTs") as String 95 | val reactChannel = reactSlackMap.inverse.get(slackTs) 96 | if(reactChannel === null) { 97 | if(slackTs.empty) { 98 | /* 99 | * No threadTs means we are in the top-level conversation 100 | */ 101 | SlackPlatform.Reply("You cannot reply in the top-level conversation, please use the dedicated threads") 102 | } else { 103 | SlackPlatform.Reply("_Sorry, I cannot forward your message, the client may have closed the session_") 104 | } 105 | } else { 106 | ReactPlatform.PostMessage("[Real Human " + context.get("chat").get("username") + "] " + intent.matchedInput, reactChannel) 107 | } 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /outdated/ReactSlackLiveChat/src/ReactSlackLiveChat.intent: -------------------------------------------------------------------------------- 1 | Library ReactSlackLiveChat 2 | 3 | intent XatkitQuestion { 4 | inputs { 5 | "I am looking for a good bot solution" 6 | } 7 | } 8 | 9 | intent WhoIsBehindXatkit { 10 | inputs { 11 | "Who is behind Xatkit?" 12 | } 13 | } --------------------------------------------------------------------------------