Commit 4c3c9e31 authored by Eelco van der Wel's avatar Eelco van der Wel :speech_balloon:
Browse files

Merge branch 'dev' into 'refactor'

# Conflicts:
#   whatsapp/plugin.py
parents 8041ae0a 2233934b
Showing with 50 additions and 0 deletions
+50 -0
src/qr_code
example_message_config.json
whatsapp/data/
test/data/*
......
......@@ -27,4 +27,10 @@ simulate_run_plugin_from_frontend --config_file="example_config.json"
Go to `localhost:8000/qr`, and scan the QR code (with a time limit of 20 seconds)
## Sending messages
To send a whatsapp message (with a running and authenticated plugin), do:
```
send_message_action --config="example_message_config.json"
```
......@@ -17,4 +17,5 @@ setup(name='whatsapp',
"pytest"
],
packages=setuptools.find_packages(),
entry_points = { 'console_scripts': ["send_message_action=whatsapp.cli:send_message_action"]}
)
from fastscript import call_parse, Param
from pymemri.data.central_schema import Message, Account
from pymemri.pod.client import PodClient
from pymemri.data.itembase import Edge
from pymemri.data.basic import read_json
@call_parse
def send_message_action(
database_key: Param("database key", str)=None,
owner_key: Param("owner key", str)=None,
config: Param("config", str)=None,
service: Param("service", str)=None,
content: Param("service", str)=None,
phone_number: Param("phone_number", str)=None
):
print("CREATING SEND MESSAGE ITEM")
if database_key and owner_key:
print("pod credentials from from args")
client = PodClient(database_key=database_key, owner_key=owner_key)
else:
client = PodClient.from_local_keys()
if config:
dict = read_json(config)
print(dict)
service = dict.get("service", service)
phone_number = dict.get("phone_number", phone_number)
content = dict.get("content", content)
assert phone_number, "provide a valid phone number either via cli or example_message_config.json"
message = Message(sendStatus="toSend", service=service, content=content)
account = Account(phoneNumber=phone_number)
edge = Edge(message, account, "receiver")
client.bulk_action(create_items=[message, account], create_edges=[edge])
......@@ -123,6 +123,9 @@ class WABinaryReader:
# TODO: Fix this hack for this edge case properly
if i == b'Server':
i = 'Server'
if isinstance(i, bytes):
# Hacky fix for unknown phone numbers (bytes to string) . e.g. b'+14151111' -> "+14151111"
i = str(i)[2:-1]
return i + '@' + j
elif tag == WATags.NIBBLE_8 or tag == WATags.HEX_8:
return self.readPacked8(tag);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment