diff --git a/connectors/connector-waku/bin/boot_waku_node_in_docker b/connectors/connector-waku/bin/boot_waku_node_in_docker index b5e907a..d24097c 100755 --- a/connectors/connector-waku/bin/boot_waku_node_in_docker +++ b/connectors/connector-waku/bin/boot_waku_node_in_docker @@ -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" diff --git a/connectors/connector-waku/connector_waku/commands/sendMessage.py b/connectors/connector-waku/connector_waku/commands/sendMessage.py index 529824b..c487736 100644 --- a/connectors/connector-waku/connector_waku/commands/sendMessage.py +++ b/connectors/connector-waku/connector_waku/commands/sendMessage.py @@ -31,35 +31,39 @@ class SendMessage: message_type: str recipient: list[str] + 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": 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 + 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: - 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}], - "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 + 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 ({