Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SendMessageMutation Error #180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions poe_api_wrapper/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def send_request(self, path: str, query_name: str="", variables: dict={}, file_f

except Exception as e:
if isinstance(e, ReadTimeout):
if query_name == "SendMessageMutation":
if query_name == "sendMessageMutation":
logger.error(f"Failed to send message {variables['query']} due to ReadTimeout")
raise e
else:
Expand Down Expand Up @@ -705,7 +705,7 @@ def send_message(self, bot: str, message: str, chatId: int=None, chatCode: str=N
"existingMessageAttachmentsIds":[],
"messagePointsDisplayPrice": msgPrice
}
message_data = self.send_request(apiPath, 'SendMessageMutation', variables, file_form)
message_data = self.send_request(apiPath, 'sendMessageMutation', variables, file_form)

if message_data["data"] != None and message_data["data"]["messageEdgeCreate"]["status"] == "message_points_display_price_mismatch":
msgPrice = message_data["data"]["messageEdgeCreate"]["bot"]["messagePointLimit"]["displayMessagePointPrice"]
Expand All @@ -721,7 +721,7 @@ def send_message(self, bot: str, message: str, chatId: int=None, chatCode: str=N
"existingMessageAttachmentsIds":[],
"messagePointsDisplayPrice": msgPrice
}
message_data = self.send_request(apiPath, 'SendMessageMutation', variables, file_form)
message_data = self.send_request(apiPath, 'sendMessageMutation', variables, file_form)

if message_data["data"] == None and message_data["errors"]:
raise ValueError(
Expand Down Expand Up @@ -780,7 +780,7 @@ def send_message(self, bot: str, message: str, chatId: int=None, chatCode: str=N
}

try:
message_data = self.send_request(apiPath, 'SendMessageMutation', variables, file_form)
message_data = self.send_request(apiPath, 'sendMessageMutation', variables, file_form)
if message_data["data"] != None and message_data["data"]["messageEdgeCreate"]["status"] == "message_points_display_price_mismatch":
msgPrice = message_data["data"]["messageEdgeCreate"]["bot"]["messagePointLimit"]["displayMessagePointPrice"]
variables = {
Expand All @@ -795,7 +795,7 @@ def send_message(self, bot: str, message: str, chatId: int=None, chatCode: str=N
"existingMessageAttachmentsIds":[],
"messagePointsDisplayPrice": msgPrice
}
message_data = self.send_request(apiPath, 'SendMessageMutation', variables, file_form)
message_data = self.send_request(apiPath, 'sendMessageMutation', variables, file_form)

if message_data["data"] == None and message_data["errors"]:
raise RuntimeError(f"An unknown error occurred. Raw response data: {message_data}")
Expand Down
10 changes: 5 additions & 5 deletions poe_api_wrapper/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async def send_request(self, path: str, query_name: str="", variables: dict={},

except Exception as e:
if isinstance(e, ReadTimeout):
if query_name == "SendMessageMutation":
if query_name == "sendMessageMutation":
logger.error(f"Failed to send message {variables['query']} due to ReadTimeout")
raise e
else:
Expand Down Expand Up @@ -738,7 +738,7 @@ async def send_message(self, bot: str, message: str, chatId: int=None, chatCode:
"existingMessageAttachmentsIds":[],
"messagePointsDisplayPrice": msgPrice
}
message_data = await self.send_request(apiPath, 'SendMessageMutation', variables, file_form)
message_data = await self.send_request(apiPath, 'sendMessageMutation', variables, file_form)

if message_data["data"] != None and message_data["data"]["messageEdgeCreate"]["status"] == "message_points_display_price_mismatch":
msgPrice = message_data["data"]["messageEdgeCreate"]["bot"]["messagePointLimit"]["displayMessagePointPrice"]
Expand All @@ -754,7 +754,7 @@ async def send_message(self, bot: str, message: str, chatId: int=None, chatCode:
"existingMessageAttachmentsIds":[],
"messagePointsDisplayPrice": msgPrice
}
message_data = await self.send_request(apiPath, 'SendMessageMutation', variables, file_form)
message_data = await self.send_request(apiPath, 'sendMessageMutation', variables, file_form)

if message_data["data"] == None and message_data["errors"]:
raise ValueError(
Expand Down Expand Up @@ -813,7 +813,7 @@ async def send_message(self, bot: str, message: str, chatId: int=None, chatCode:
}

try:
message_data = await self.send_request(apiPath, 'SendMessageMutation', variables, file_form)
message_data = await self.send_request(apiPath, 'sendMessageMutation', variables, file_form)
if message_data["data"] != None and message_data["data"]["messageEdgeCreate"]["status"] == "message_points_display_price_mismatch":
msgPrice = message_data["data"]["messageEdgeCreate"]["bot"]["messagePointLimit"]["displayMessagePointPrice"]
variables = {
Expand All @@ -828,7 +828,7 @@ async def send_message(self, bot: str, message: str, chatId: int=None, chatCode:
"existingMessageAttachmentsIds":[],
"messagePointsDisplayPrice": msgPrice
}
message_data = await self.send_request(apiPath, 'SendMessageMutation', variables, file_form)
message_data = await self.send_request(apiPath, 'sendMessageMutation', variables, file_form)

if message_data["data"] == None and message_data["errors"]:
raise RuntimeError(f"An unknown error occurred. Raw response data: {message_data}")
Expand Down
9 changes: 6 additions & 3 deletions poe_api_wrapper/queries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import orjson, random
import random

import orjson


QUERIES = {
"RegenerateMessageMutation": "056f5f4b6a39ca7786a4f0b2ef37eee401c81d6086cd78ffc12fe2ce0bccb1fd",
Expand Down Expand Up @@ -120,7 +123,7 @@
"SearchResultsListPaginationQuery": "f6d4b5bbec10438548a5f8feedac11001878efe2e31a3d0ecd7680a4decb5c66",
"SearchResultsMainQuery": "7ee1c22fd46693de7869ce0305d0209b7fda41ef91389110cd989804194fcaf8",
"SelectorTestPageQuery": "9ec86fe8e3d0d3b264d0fab0feb73e38c86d616c7c3d8340d7a6146bd8445ed3",
"SendMessageMutation": "b4aff2855bc876361737bcbf5f9310b5da4d3250923894ecb8f339de4c2e3fa3",
"sendMessageMutation": "b5694554bb2d91d0226fed35139f1d038fdd0fa30148be02546d0e2afa3e72a4",
"SendVerificationCodeMutation": "d418fa3d2357d089b20065226041180573fa0b0382914a90cf905435281af520",
"SetPrimaryEmailMutation": "01e75a6d937351b304ca9cc0b231e43587a5923e7f8618863bdf996df38d28b5",
"SettingsDefaultBotSectionMutation": "4084604e8741af8650ac6b4236cdfa13c91a70cf1c63ad8a368706a386d0887e",
Expand Down Expand Up @@ -189,4 +192,4 @@ def generate_recv_payload(variables):
"extra_data": {},
},
})
return orjson.dumps(payload).decode("utf-8")
return orjson.dumps(payload).decode("utf-8")