Move body of Client._doSendRequest to State
This commit is contained in:
@@ -1056,30 +1056,11 @@ class Client(object):
|
|||||||
|
|
||||||
def _doSendRequest(self, data, get_thread_id=False):
|
def _doSendRequest(self, data, get_thread_id=False):
|
||||||
"""Send the data to `SendURL`, and returns the message ID or None on failure."""
|
"""Send the data to `SendURL`, and returns the message ID or None on failure."""
|
||||||
j = self._post("/messaging/send/", data)
|
mid, thread_id = self._state._do_send_request(data)
|
||||||
|
if get_thread_id:
|
||||||
# update JS token if received in response
|
return mid, thread_id
|
||||||
fb_dtsg = get_jsmods_require(j, 2)
|
else:
|
||||||
if fb_dtsg is not None:
|
return mid
|
||||||
self._state.fb_dtsg = fb_dtsg
|
|
||||||
|
|
||||||
try:
|
|
||||||
message_ids = [
|
|
||||||
(action["message_id"], action["thread_fbid"])
|
|
||||||
for action in j["payload"]["actions"]
|
|
||||||
if "message_id" in action
|
|
||||||
]
|
|
||||||
if len(message_ids) != 1:
|
|
||||||
log.warning("Got multiple message ids' back: {}".format(message_ids))
|
|
||||||
if get_thread_id:
|
|
||||||
return message_ids[0]
|
|
||||||
else:
|
|
||||||
return message_ids[0][0]
|
|
||||||
except (KeyError, IndexError, TypeError) as e:
|
|
||||||
raise FBchatException(
|
|
||||||
"Error when sending message: "
|
|
||||||
"No message IDs could be found: {}".format(j)
|
|
||||||
)
|
|
||||||
|
|
||||||
def send(self, message, thread_id=None, thread_type=ThreadType.USER):
|
def send(self, message, thread_id=None, thread_type=ThreadType.USER):
|
||||||
"""Send message to a thread.
|
"""Send message to a thread.
|
||||||
|
@@ -297,3 +297,26 @@ class State(object):
|
|||||||
(data[_util.mimetype_to_key(data["filetype"])], data["filetype"])
|
(data[_util.mimetype_to_key(data["filetype"])], data["filetype"])
|
||||||
for data in j["metadata"]
|
for data in j["metadata"]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _do_send_request(self, data):
|
||||||
|
j = self._post("/messaging/send/", data)
|
||||||
|
|
||||||
|
# update JS token if received in response
|
||||||
|
fb_dtsg = _util.get_jsmods_require(j, 2)
|
||||||
|
if fb_dtsg is not None:
|
||||||
|
self.fb_dtsg = fb_dtsg
|
||||||
|
|
||||||
|
try:
|
||||||
|
message_ids = [
|
||||||
|
(action["message_id"], action["thread_fbid"])
|
||||||
|
for action in j["payload"]["actions"]
|
||||||
|
if "message_id" in action
|
||||||
|
]
|
||||||
|
if len(message_ids) != 1:
|
||||||
|
log.warning("Got multiple message ids' back: {}".format(message_ids))
|
||||||
|
return message_ids[0]
|
||||||
|
except (KeyError, IndexError, TypeError) as e:
|
||||||
|
raise _exception.FBchatException(
|
||||||
|
"Error when sending message: "
|
||||||
|
"No message IDs could be found: {}".format(j)
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user