send a contact request whenever sending a waku message w/ burnettk
This commit is contained in:
parent
e5c503d737
commit
1c20e93fb8
|
@ -13,4 +13,4 @@ docker \
|
|||
--name spiffworkflow-waku-node \
|
||||
-d \
|
||||
spiffworkflow-waku-node:latest \
|
||||
--seed-phrase "waku ftw we are about to send a one on one message baby oh yeah"
|
||||
--seed-phrase "search symbol claim wall raccoon mesh thumb luggage endorse live horse grid"
|
||||
|
|
|
@ -31,35 +31,39 @@ class SendMessage:
|
|||
message_type: str
|
||||
recipient: list[str]
|
||||
|
||||
def execute(self, config, task_data):
|
||||
"""Execute."""
|
||||
responses = []
|
||||
all_calls_returned_200 = True
|
||||
for rec in self.recipient:
|
||||
def send_message(self, message_type_to_use: str, rec: str, message_to_send: str) -> None:
|
||||
url = f'{current_app.config["WAKU_BASE_URL"]}'
|
||||
headers = {"Accept": "application/json", "Content-type": "application/json"}
|
||||
request_body = {
|
||||
"jsonrpc": "2.0",
|
||||
"method": self.message_type,
|
||||
"params": [{"id": rec, "message": self.message}],
|
||||
"method": message_type_to_use,
|
||||
"params": [{"id": rec, "message": message_to_send}],
|
||||
"id": 1,
|
||||
}
|
||||
|
||||
try:
|
||||
raw_response = requests.post(url, json.dumps(request_body), headers=headers)
|
||||
status_code = raw_response.status_code
|
||||
if status_code != 200:
|
||||
all_calls_returned_200 = False
|
||||
parsed_response = json.loads(raw_response.text)
|
||||
response = parsed_response
|
||||
except Exception as ex:
|
||||
response = {"error": str(ex)}
|
||||
status_code = 500
|
||||
return (response, status_code)
|
||||
|
||||
def execute(self, config, task_data):
|
||||
"""Execute."""
|
||||
responses = []
|
||||
all_calls_returned_200 = True
|
||||
for rec in self.recipient:
|
||||
response, status_code = self.send_message('wakuext_sendContactRequest', rec, 'Contact Request')
|
||||
if status_code == 200:
|
||||
response, status_code = self.send_message(self.message_type, rec, self.message)
|
||||
if status_code != 200:
|
||||
all_calls_returned_200 = False
|
||||
|
||||
responses.append({
|
||||
"response": response,
|
||||
"node_returned_200": True,
|
||||
"status": status_code,
|
||||
})
|
||||
return ({
|
||||
|
|
Loading…
Reference in New Issue