Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b76159
commit d998e04
Showing
7 changed files
with
113 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
body.home | ||
{ | ||
background-color: #00356B; | ||
} | ||
|
||
.c3 { | ||
font-weight: 700; | ||
font-family: "Arial"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/gob" | ||
"fmt" | ||
"github.com/Baozisoftware/qrcode-terminal-go" | ||
"github.com/Rhymen/go-whatsapp" | ||
"os" | ||
"time" | ||
) | ||
|
||
func main() { | ||
//create new WhatsApp connection | ||
wac, err := whatsapp.NewConn(5 * time.Second) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error creating connection: %v\n", err) | ||
return | ||
} | ||
|
||
//load saved session | ||
session, err := readSession() | ||
if err == nil { | ||
//restore session | ||
session, err = wac.RestoreSession(session) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "restoring failed: %v\n", err) | ||
return | ||
} | ||
} else { | ||
//no saved session -> regular login | ||
qr := make(chan string) | ||
go func() { | ||
terminal := qrcodeTerminal.New() | ||
terminal.Get(<-qr).Print() | ||
}() | ||
session, err = wac.Login(qr) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error during login: %v\n", err) | ||
} | ||
} | ||
|
||
//save session | ||
err = writeSession(session, string(session.Wid)) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error saving session: %v\n", err) | ||
} | ||
|
||
fmt.Printf("login successful, session: %v\n", session) | ||
} | ||
func readSession() (whatsapp.Session, error) { | ||
session := whatsapp.Session{} | ||
file, err := os.Open(os.TempDir() + "/"+ session.Wid +".gob") | ||
if err != nil { | ||
return session, err | ||
} | ||
defer file.Close() | ||
decoder := gob.NewDecoder(file) | ||
err = decoder.Decode(&session) | ||
if err != nil { | ||
return session, err | ||
} | ||
return session, nil | ||
} | ||
|
||
func writeSession(session whatsapp.Session, jid string) error { | ||
file, err := os.Create(os.TempDir() + "/"+ jid +".gob") | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
encoder := gob.NewEncoder(file) | ||
err = encoder.Encode(session) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |