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

Fixes 3 issues #3

Merged
merged 1 commit into from
Dec 3, 2022
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env/
examplestore.db
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ func (mycli *MyClient) eventHandler(evt interface{}) {
switch v := evt.(type) {
case *events.Message:
newMessage := v.Message
msg := newMessage.GetExtendedTextMessage().GetText()
fmt.Println("Message received:", msg)
msg := newMessage.GetConversation()
fmt.Println("Message from:", v.Info.Sender.User, "->", msg)
if msg == "" {
return
}
// Make a http request to localhost:5001/chat?q= with the message, and send the response
// URL encode the message
urlEncoded := url.QueryEscape(msg)
url := "http://localhost:5001/chat?q=" + urlEncoded
// Make the request
resp, err := http.Get("http://localhost:5001/chat?q=" + urlEncoded)
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error making request:", err)
return
Expand All @@ -51,6 +55,8 @@ func (mycli *MyClient) eventHandler(evt interface{}) {
newMsg := buf.String()
// encode out as a string
response := &waProto.Message{Conversation: proto.String(string(newMsg))}
fmt.Println("Response:", response)

userJid := types.NewJID(v.Info.Sender.User, types.DefaultUserServer)
mycli.WAClient.SendMessage(context.Background(), userJid, "", response)

Expand Down
10 changes: 7 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ def get_input_box():
return PAGE.query_selector("div[class*='PromptTextarea__TextareaWrapper']").query_selector("textarea")

def is_logged_in():
# See if we have a textarea with data-id="root"
return get_input_box() is not None
try:
# See if we have a textarea with data-id="root"
return get_input_box() is not None
except AttributeError:
return False

def send_message(message):
# Send the message
box = get_input_box()
box.click()
box.fill(message)
box.press("Enter")
while PAGE.query_selector(".result-streaming") is not None:
time.sleep(0.1)

def get_last_message():
"""Get the latest message"""
Expand All @@ -42,7 +47,6 @@ def chat():
message = flask.request.args.get("q")
print("Sending message: ", message)
send_message(message)
time.sleep(10) # TODO: there are about ten million ways to be smarter than this
response = get_last_message()
print("Response: ", response)
return response
Expand Down