Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatBot socket closed and errorReceived callbacks added #3

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}

Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ buildscript
{
google()
jcenter()
maven { url "https://jitpack.io" }
}

dependencies
Expand All @@ -21,6 +22,7 @@ allprojects
{
google()
jcenter()
maven { url "https://jitpack.io" }
}

tasks.withType(Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -176,20 +188,22 @@ class DirectLineChatbot(val secret: String)
override fun onClose(code: Int, reason: String?, remote: Boolean)
{
log("CLOSE")
callback.onClosed()
}

override fun onMessage(message: 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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