public class Conversation
extends java.lang.Object
To obtain an instance, use Bots.getConversation()
.
Bots.init(Application, Settings, BotsCallback)
must have been called prior to retrieving the conversation object.
To send a message, use sendMessage(Message)
with a Message
object.
Example:
Bots.getConversation().sendMessage(new Message("Hello World!"));
Modifier and Type | Class and Description |
---|---|
static interface |
Conversation.Delegate
Delegate for events related to the conversation.
|
static interface |
Conversation.MessageModifierDelegate
Delegate for events related to sending and displaying of specific messages.
|
static interface |
Conversation.ViewDelegate
Delegate for events related to the conversation view.
|
Modifier and Type | Method and Description |
---|---|
void |
addMessage(Message message)
Adds a new message to the conversation without sending it.
|
void |
botsHidden()
Notifies the delegate when Bots Conversation is hidden
|
void |
botsShown()
Notifies the delegate when Bots Conversation is shown
|
java.util.Date |
getAppMakerLastRead()
Date when the business last read the user messages
|
Conversation.Delegate |
getDelegate()
The delegate set via
setDelegate(Delegate) . |
Conversation.MessageModifierDelegate |
getMessageModifierDelegate()
The delegate set via
setMessageModifierDelegate(MessageModifierDelegate) . |
java.util.List<Message> |
getMessages()
The list of Message objects representing the conversation.
|
int |
getUnreadCount()
Count of unread messages in the conversation.
|
Conversation.ViewDelegate |
getViewDelegate()
The delegate set via
setViewDelegate(ViewDelegate) |
boolean |
isBotsShown()
Returns
true if the Bots UI is currently shown |
void |
loadCardSummary()
Loads billing info (if exists) to display last4 in credit form.
|
void |
markAllAsRead()
Marks all unread messages as read.
|
void |
markAsRead(Message message)
Marks an unread message as read.
|
void |
postback(MessageAction action,
BotsCallback callback)
Triggers MessageAction postback.
|
void |
processPayment(CreditCard creditCard,
MessageAction action)
Processes a credit card payment.
|
void |
removeMessage(Message message)
Removes a failed or unsent message from the conversation.
|
Message |
retryMessage(Message message)
Retries a message that failed to send.
|
void |
sendMessage(Message message)
Adds a new message to the conversation.
|
void |
setBotsUIDelegate(Conversation.Delegate botsUIDelegate)
Sets the
Conversation.Delegate used by the bots-ui package |
void |
setDelegate(Conversation.Delegate delegate)
Sets the
Conversation.Delegate |
void |
setMessageModifierDelegate(Conversation.MessageModifierDelegate messageModifierDelegate)
Sets the
Conversation.MessageModifierDelegate |
void |
setViewDelegate(Conversation.ViewDelegate viewDelegate)
Sets the
Conversation.ViewDelegate |
void |
startTyping()
Notify the server that the user is typing.
|
void |
stopTyping()
Notify the server that the user has finished typing.
|
void |
triggerAction(MessageAction action)
Triggers message action resulting from a click.
|
void |
uploadFile(Message fileMessage,
BotsCallback callback)
/**
Uploads a user file to the conversation.
|
void |
uploadImage(Message imageMessage,
BotsCallback callback)
Uploads a user image to the conversation.
|
public void setDelegate(Conversation.Delegate delegate)
Conversation.Delegate
This delegate will be notified before the delegate set using setBotsUIDelegate(Delegate)
Any delegate functions with the form boolean return type will prevent notification of botsUIDelegate
delegate
- The delegatepublic void setBotsUIDelegate(Conversation.Delegate botsUIDelegate)
Conversation.Delegate
used by the bots-ui package
The primary use of this property is to notify the Bots UI of changes in the Conversation
Note that this delegate will be notified after the delegate set using setDelegate(Delegate)
botsUIDelegate
- The botsUIDelegatepublic void setMessageModifierDelegate(Conversation.MessageModifierDelegate messageModifierDelegate)
Conversation.MessageModifierDelegate
The delegate allows you to change the way messages are displayed or sent to Bots.
messageModifierDelegate
- The messageModifierDelegatepublic void setViewDelegate(Conversation.ViewDelegate viewDelegate)
Conversation.ViewDelegate
The delegate allows you to be notified of events related to the conversation view
viewDelegate
- The viewDelegatepublic Conversation.Delegate getDelegate()
setDelegate(Delegate)
.public Conversation.MessageModifierDelegate getMessageModifierDelegate()
setMessageModifierDelegate(MessageModifierDelegate)
.public Conversation.ViewDelegate getViewDelegate()
setViewDelegate(ViewDelegate)
public java.util.List<Message> getMessages()
public int getUnreadCount()
The primary use of this property is to be able to display an indicator when the conversation has unread messages.
public java.util.Date getAppMakerLastRead()
public void markAllAsRead()
Marks all unread messages as read, and notifies that the unread count changed.
public void markAsRead(Message message)
Marks an unread message as read, and notifies that the unread count changed.
public void sendMessage(Message message)
For each message added using sendMessage, a notification will be fired indicating the success or failure status of the upload.
message
- The message to sendpublic Message retryMessage(Message message)
The failed message will be removed from the message list, and a new message will be constructed with the same text as the failed message. A notification will be fired indicating the success or failure status of the upload.
message
- The failed messagepublic void addMessage(Message message)
message
- The message to addpublic void removeMessage(Message message)
message
- The message to removepublic void uploadImage(Message imageMessage, BotsCallback callback)
For each image upload, provided BotsCallback
will be called with status code, error and the resulting message
imageMessage
- The imageMessage to uploadcallback
- The callback, to be called with BotsCallback.Response
getData() of type Message
, null in case of errorMessage
,
BotsCallback
public void uploadFile(Message fileMessage, BotsCallback callback)
For each file upload, provided BotsCallback
will be called with status code, error and the resulting message
fileMessage
- The fileMessage to uploadcallback
- The callback, to be called with BotsCallback.Response
getData() of type Message
, null in case of errorMessage
,
BotsCallback
public void startTyping()
Typing updates are automatically throttled, so you may call this method as often as necessary. The typing stop event will automatically fire 10 seconds after the most recent call to this method.
stopTyping()
public void stopTyping()
If the user was not flagged as typing recently, this method will result in a no-op.
startTyping()
public void processPayment(CreditCard creditCard, MessageAction action)
creditCard
- The credit card objectaction
- The message actionCreditCard
,
MessageAction
public void triggerAction(MessageAction action)
action
- The message actionMessageAction
public void loadCardSummary()
public void postback(MessageAction action, BotsCallback callback)
MessageAction
,
BotsCallback
public void botsShown()
Used by the bots-ui package to notify the Conversation.Delegate when Bots is shown
public void botsHidden()
Used by the bots-ui package to notify the Conversation.Delegate when Bots is hidden
public boolean isBotsShown()
true
if the Bots UI is currently showntrue
if the Bots UI is currently shown, false
otherwise