Message¶
-
class
watson_workspace_sdk.models.message.
Message
(id: str = '')¶ Bases:
object
Used for creating,updating and deleting Messages
Attributes
- content : str
- Title/Heading of the Annotation
- content_type : str
- Message content type, appMessage by default
- annotations : Annotation
- List of annotations attributed to the message, usually created by Watson API
- created : datetime
- Message creation time
- updated : datetime
- Message modification time
- created_by : Person
- Message creator
- id : str
- Message Id
- updated_by : Person
- Person who last modified message
- version : str
- Message version
Methods
-
add_focus
(phrase: str = '', *, lens: str = 'Opportunity', category: str = 'Inquiry', actions: str = '"test"', confidence: float = 0.99, payload: str = '', start: int = 0, end: int = 0, version: int = 1, hidden: str = 'false') → None¶ Parameters: - phrase – Subset of message to mark as focus topic
- lens – Lens to view request, options are ActionRequest, Question, and Commitment
- category –
- actions – Watson Workspace Action to initiate when focus is triggered
- confidence – Confidence level
- payload –
- start – inclusive index (including markdown) at which to start as the focus topic
- end – inclusive index (including markdown) at which to end as the focus topic
- version – Focus version
- hidden – Is focus hidden
Returns: None
>>> my_message.add_focus(start=55, end=67, actions='"check_weather"')
-
add_reaction
(reaction: str) → None¶ Adds a supported unicode character as a reaction to a message :param reaction: Unicode reaction to append to message :return: None >>> my_message.add_reaction(“👍”)
-
count_reaction
(reaction: str) → int¶ Parameters: reaction – Unicode reaction to verify e.g. 🌧️ Returns: Number of times reaction has been added to message Return type: int
-
classmethod
create
(space_id: str, title='title', text='text', color='#36a64f', actor='') → watson_workspace_sdk.models.message.Message¶ Sends a message to Watson Workspace and then creates a Message object
Parameters: - space_id – Target space Id
- title – Message Title
- text – Message body
- color – Border color for message
- actor – Message sender
Returns: Message object of sent message
Return type: Example: >>> my_message = Message.create(space_id=space_id, title="Today's Weather", text="Rain", actor="Rain App", color="blue")
-
classmethod
from_json
(response_json) → watson_workspace_sdk.models.message.Message¶ Creates a Message object from JSON. Useful when retrieving a list of messages. Does not send a messsage to Watson Workspace :param response_json: JSON Message Object :return: Message :rtype: Message
-
classmethod
get
(message_id: str) → watson_workspace_sdk.models.message.Message¶ Retrieves existing message from Watson Workspace
Parameters: message_id – Message Id to retrieve Returns: Message Return type: Message >>> my_message = Message.get(message_id)
-
static
message_with_annotation
(*, conversation_id: str, target_user_id: str, target_dialog_id: str, annotation: watson_workspace_sdk.models.genericAnnotation.Annotation) → None¶ Parameters: - conversation_id – Space Id
- target_user_id – User Id
- target_dialog_id – Reference to the annotation event that initiated call, provided by webhook event
- annotation – Annotation to send
Returns: None
>>> test_annotation = Annotation("Test Annotation", "Here's a test annotation with a button") >>> test_annotation.add_button("Click here", "button_test_event") >>> Message.message_with_annotation(conversation_id=webhook_event.space_id, target_user_id=webhook_event.user_id,target_dialog_id=annotation.get("targetDialogId"), annotation=test_annotation)
-
static
message_with_attachment
(*, conversation_id: str, target_user_id: str, target_dialog_id: str, cards: List[watson_workspace_sdk.models.card.Card]) → None¶ https://developer.watsonwork.ibm.com/docs/tutorials/action-fulfillment :param conversation_id: Space Id :param target_user_id: User Id :param target_dialog_id: Reference to the annotation event that initiated call, provided by webhook event :param cards: Cards to be added :return: None
>>> new_card = Card("Here's test card 1 ", "A smaller title", "Body") >>> new_card.add_button("Test Button", "test_button_event") >>> attached_message = Message.message_with_attachment(conversation_id=webhook_event.space_id, target_dialog_id=annotation.get("targetDialogId"), target_user_id=annotation.get("targetDialogId"), cards=[new_card])
-
remove_reaction
(reaction: str) → None¶ Removes a supported unicode character as a reaction to a message assuming user has added that character previously :param reaction: Reaction to remove :return: None
>>> my_message.remove_reaction("👍")
-
to_json
() → str¶ Formats a message object into the format expect by watson workspace.