Skip to content

Commit

Permalink
Merge pull request #139 from livechat/Bug_fix_response_timeout
Browse files Browse the repository at this point in the history
Bug fix regarding response_timeout
  • Loading branch information
marcindebski authored Jul 26, 2024
2 parents 75bf5de + 64c98de commit e4ef0bf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions livechat/utils/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def open(self,

def send(self, request: dict, opcode=ABNF.OPCODE_TEXT) -> dict:
'''
Sends message, assigining a random request ID, fetching and returning response(s).
Sends message, assigning a random request ID, fetching and returning response(s).
Args:
request (dict): message to send. If you set opcode to OPCODE_TEXT,
data must be utf-8 string or unicode.
Expand All @@ -77,6 +77,7 @@ def send(self, request: dict, opcode=ABNF.OPCODE_TEXT) -> dict:
RtmResponse: RTM response structure (`request_id`, `action`,
`type`, `success` and `payload` properties)
'''
response_timeout = self.response_timeout
request_id = str(random.randint(1, 9999999999))
request.update({'request_id': request_id})
request_json = json.dumps(request, indent=4)
Expand All @@ -88,9 +89,9 @@ def send(self, request: dict, opcode=ABNF.OPCODE_TEXT) -> dict:
(item
for item in self.messages if item.get('request_id') == request_id
and item.get('type') == 'response'),
None)) and self.response_timeout > 0:
None)) and response_timeout > 0:
sleep(0.2)
self.response_timeout -= 0.2
response_timeout -= 0.2
logger.info(f'\nRESPONSE:\n{json.dumps(response, indent=4)}')
return RtmResponse(response)

Expand Down

0 comments on commit e4ef0bf

Please sign in to comment.