From 3b820472b14cb736e658e5a3841d257eb203d57e Mon Sep 17 00:00:00 2001 From: Greg Dingyu Zhang Date: Mon, 4 Dec 2017 09:51:32 -0500 Subject: [PATCH] Customized time-stamp input Add default time-stamp argument = "None", in case user wants to input customized time-stamp, instead of system's, the API shall allow. --- chatbase/base_message.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/chatbase/base_message.py b/chatbase/base_message.py index 2c1a454..0c02edc 100644 --- a/chatbase/base_message.py +++ b/chatbase/base_message.py @@ -36,9 +36,8 @@ class MessageTypes(object): USER = "user" AGENT = "agent" - class Message(object): - """Base Message. + """Base Message. modified based on older version Define attributes present on all variants of the Message Class. """ @@ -48,7 +47,8 @@ def __init__(self, message="", intent="", version="", - user_id=""): + user_id="", + time_stamp=None): self.api_key = api_key self.platform = platform self.message = message @@ -57,7 +57,8 @@ def __init__(self, self.user_id = user_id self.not_handled = False self.feedback = False - self.time_stamp = Message.get_current_timestamp() + if time_stamp == None: + self.time_stamp = Message.get_current_timestamp() self.type = MessageTypes.USER @staticmethod @@ -117,9 +118,8 @@ def send(self): data=self.to_json(), headers=Message.get_content_type()) - class MessageSet(object): - """Message Set. + """Message Set. modified based on older version Add messages to a set and send to the Batch API. """ @@ -134,14 +134,15 @@ def __init__(self, self.user_id = user_id self.messages = [] - def new_message(self, intent="", message=""): + def new_message(self, intent="", message="", time_stamp=None): """Add a message to the internal messages list and return it""" self.messages.append(Message(api_key=self.api_key, platform=self.platform, version=self.version, user_id=self.user_id, intent=intent, - message=message)) + message=message, + time_stamp=time_stamp)) return self.messages[-1] def to_json(self):