diff --git a/app/src/main/java/com/smartnsoft/directlinechatbotapp/MainJavaActivity.java b/app/src/main/java/com/smartnsoft/directlinechatbotapp/MainJavaActivity.java index 22cd819..9fce3fb 100644 --- a/app/src/main/java/com/smartnsoft/directlinechatbotapp/MainJavaActivity.java +++ b/app/src/main/java/com/smartnsoft/directlinechatbotapp/MainJavaActivity.java @@ -38,10 +38,19 @@ public void onStarted() } @Override - public void onMessageReceived(@NotNull String message) - { + public void onClosed() { + Log.d("CHATBOT","Socket Closed") + } + + @Override + public void onMessageReceived(@NotNull MessageActivity message) { Log.d("CHATBOT", message); } + + @Override + public void onErrorReceived(String error) { + Log.e("CHATBOT", error) + } }); } } diff --git a/app/src/main/kotlin/com/smartnsoft/directlinechatbotapp/MainActivity.kt b/app/src/main/kotlin/com/smartnsoft/directlinechatbotapp/MainActivity.kt index 9221758..b0b347e 100644 --- a/app/src/main/kotlin/com/smartnsoft/directlinechatbotapp/MainActivity.kt +++ b/app/src/main/kotlin/com/smartnsoft/directlinechatbotapp/MainActivity.kt @@ -32,10 +32,18 @@ class MainActivity : chatbot.send("Bonjour !") } - override fun onMessageReceived(message: String) + override fun onClosed() { + Log.d("CHATBOT", "Socket Closed") + } + + override fun onMessageReceived(message: MessageActivity) { Log.d("CHATBOT", message) } + + override fun onErrorReceived(error: String) { + Log.e("CHATBOT", error) + } }) } diff --git a/build.gradle b/build.gradle index 9656314..a3f4c00 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ buildscript { google() jcenter() + maven { url "https://jitpack.io" } } dependencies @@ -21,6 +22,7 @@ allprojects { google() jcenter() + maven { url "https://jitpack.io" } } tasks.withType(Javadoc) diff --git a/directline-chatbot-sdk/src/main/kotlin/com/smartnsoft/directlinechatbot/DirectLineChatbot.kt b/directline-chatbot-sdk/src/main/kotlin/com/smartnsoft/directlinechatbot/DirectLineChatbot.kt index 45a4d83..71bd1e1 100644 --- a/directline-chatbot-sdk/src/main/kotlin/com/smartnsoft/directlinechatbot/DirectLineChatbot.kt +++ b/directline-chatbot-sdk/src/main/kotlin/com/smartnsoft/directlinechatbot/DirectLineChatbot.kt @@ -59,11 +59,23 @@ class DirectLineChatbot(val secret: String) */ fun onStarted() + /** + * Gets called when a not-successful connection has been made with the chatbot + */ + fun onClosed() + + /** + * Gets called every time a message *from the bot* has been received + * @message: the MessageActivity from the chatbot + */ + fun onMessageReceived(message: MessageActivity) + /** * Gets called every time a message *from the bot* has been received - * @message: the text message from the chatbot + * @error: the text message from error exception */ - fun onMessageReceived(message: String) + fun onErrorReceived(error: String) + } companion object @@ -176,6 +188,7 @@ class DirectLineChatbot(val secret: String) override fun onClose(code: Int, reason: String?, remote: Boolean) { log("CLOSE") + callback.onClosed() } override fun onMessage(message: String?) @@ -183,13 +196,14 @@ class DirectLineChatbot(val secret: String) log("MESSAGE RECEIVED : ${message}") val messageReceived = GSON.fromJson(message, MessageReceived::class.java) messageReceived?.watermark?.let { - callback?.onMessageReceived(messageReceived.activities[0].text) + callback?.onMessageReceived(messageReceived.activities[0]) } } override fun onError(ex: Exception?) { - Log.e(TAG, ex?.message) + Log.e(TAG, ex?.message?) + callback.onErrorReceived(ex.message?: "ERROR") } } webSocket?.connect() diff --git a/directline-chatbot-sdk/src/main/kotlin/com/smartnsoft/directlinechatbot/bo/MessageActivity.kt b/directline-chatbot-sdk/src/main/kotlin/com/smartnsoft/directlinechatbot/bo/MessageActivity.kt index d19ab8c..d5015b4 100644 --- a/directline-chatbot-sdk/src/main/kotlin/com/smartnsoft/directlinechatbot/bo/MessageActivity.kt +++ b/directline-chatbot-sdk/src/main/kotlin/com/smartnsoft/directlinechatbot/bo/MessageActivity.kt @@ -36,6 +36,7 @@ internal data class MessageActivity(val type: String, val from: Id, val conversation: Id, val text: String, + val speak: String?, val inputHint: String, val replyToId: String) : Serializable \ No newline at end of file