Skip to content

Commit

Permalink
Fixed multiple messages issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahesh committed Dec 12, 2023
1 parent 3920b96 commit 7ea8bd6
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,27 @@ async def handle_message(self):
"channel_type": "business_messages", "tabname": "default"})

if 'message' in request_body and 'text' in request_body['message']:
message = request_body['message']['text']
conversation_id = request_body['conversationId']
message_id = request_body['message']['messageId']
business_messages = BusinessMessages(credentials_json)
await business_messages.handle_user_message(text=message, sender_id=self.user.email, metadata=metadata,
conversation_id=conversation_id, bot=self.bot,
message_id=message_id)
create_time = request_body['message']['createTime']
if self.check_message_create_time(create_time):
message = request_body['message']['text']
conversation_id = request_body['conversationId']
message_id = request_body['message']['messageId']
business_messages = BusinessMessages(credentials_json)
await business_messages.handle_user_message(text=message, sender_id=self.user.email, metadata=metadata,
conversation_id=conversation_id, bot=self.bot,
message_id=message_id)
return {"status": "OK"}

@staticmethod
def check_message_create_time(create_time: str):
from datetime import datetime

current_time = datetime.utcnow()
message_time = datetime.strptime(create_time, '%Y-%m-%dT%H:%M:%S.%fZ')
time_difference = current_time - message_time
print(time_difference)
return True if time_difference.total_seconds() < 5 else False


class BusinessMessages:

Expand Down

0 comments on commit 7ea8bd6

Please sign in to comment.