Skip to content

Commit

Permalink
bridge,docs: add login command
Browse files Browse the repository at this point in the history
  • Loading branch information
markjoshwel committed Nov 7, 2023
1 parent e363ef8 commit 5208b26
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ to use the WhatsApp bridge:
2. install spow-whatsapp-bridge:

```text
pkg install golang git
git clone https://github.com/markjoshwel/spow-whatsapp-bridge
(cd spow-whatsapp-bridge; go build)
mkdir -p $HOME/.local/bin
mv spow-whatsapp-bridge/s+ow-whatsapp-bridge $HOME/.local/bin
pkg install golang git
git clone https://github.com/markjoshwel/spow-whatsapp-bridge
(go build; cd spow-whatsapp-bridge)
mkdir -p $HOME/.local/bin
mv spow-whatsapp-bridge/spow-whatsapp-bridge $HOME/.local/bin/s+ow-whatsapp-bridge
```

3. log into WhatsApp:

```text
s+ow-whatsapp-bridge
s+ow-whatsapp-bridge login
```

give it a minute or two to sync your history. once the screen stops scrolling, you can
safely exit with Ctrl+D.
safely exit with `Ctrl+D` or `Ctrl+C`.

4. add the following to your `$HOME/.s+ow-bridges` file:

Expand All @@ -46,6 +46,8 @@ usage:

- `s+ow-whatsapp-bridge`
normal usage; sends latest message to `wa:`-prefixed targets given in stdin
- `s+ow-whatsapp-login`
logs into WhatsApp
- `s+ow-whatsapp-bridge logout`
logs out of WhatsApp
- `s+ow-whatsapp-bridge list`
Expand Down
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func main() {
return
}

// c := make(chan os.Signal)
c := make(chan os.Signal)
input := make(chan string)
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
Expand All @@ -150,6 +150,26 @@ func main() {
}
}()

// if 'login' in os.Args, we exit here
for _, arg := range os.Args {
if arg == "login" {
for {
select {
case <-c:
log.Infof("Interrupt received, exiting")
cli.Disconnect()
return
case cmd := <-input:
if len(cmd) == 0 {
log.Infof("Stdin closed, exiting")
cli.Disconnect()
return
}
}
}
}
}

// if using as cli
args := os.Args[1:]
if len(args) > 0 {
Expand Down

0 comments on commit 5208b26

Please sign in to comment.