Compare commits

...

12 Commits

Author SHA1 Message Date
normen
c2e7d5d6b7 - fix string combination
- bump version
2021-04-10 12:31:00 +02:00
Normen Hansen
88cc6b09ae Merge pull request #42 from cetinajero/feature/customizable-backlog-msg-qty
Setting for the # of messages per backlog
2021-04-10 12:24:17 +02:00
Edgar Tinajero
646fed75a6 Fix indentation 2021-04-09 12:39:18 -06:00
Edgar Tinajero
0b5476a1c8 Setting for the # of messages per backlog
This adds a customizable setting to define how many messages to retrieve per backlog cmd execution
2021-04-09 12:36:08 -06:00
normen
8510dd40ee add license info 2021-02-20 17:03:12 +01:00
normen
ee5d675f98 bump version 2021-02-15 20:54:36 +01:00
Normen Hansen
2a3f53c4c3 Merge pull request #37 from keegancsmith/terminal-bell
add UseTerminalBell as an alternative to desktop notifications
2021-02-15 20:52:12 +01:00
Keegan Carruthers-Smith
cc71c296b2 add UseTerminalBell as an alternative to desktop notifications 2021-02-15 21:17:07 +02:00
normen
b98af9f0c7 document notifications 2020-12-08 16:59:51 +01:00
normen
4fdcd70703 cleanups 2020-12-07 23:02:44 +01:00
normen
f690d798bc more doc! 2020-12-07 22:54:09 +01:00
normen
dd6e4f54b1 Dr. Doc 🚑 2020-12-07 22:45:09 +01:00
4 changed files with 68 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ Heres some things you might expect to work that don't. Plus some other things I
- No automation of messages, no sending of messages through shell commands
- FaceBook obviously doesn't endorse or like these kinds of apps and they're likely to break when FaceBook changes stuff in their web app
## Installation / Usage
## Installation
How to get it running and how to use it
@@ -52,6 +52,46 @@ Some ways to install via package managers are supported but the installed versio
- `https://aur.archlinux.org/packages/whatscli/`
## Usage
Most information, all commands and key bindings are availabe through the in-app help, simply type `/help` and/or `/commands`.
### Login
When starting up, whatscli will immediately try to connect to the WhatsApp server to log in. Keep your phone ready to scan the appearing QR code in WhatsApp on your Phone. If you don't manage to scan the code quick enough just restart the application. If you can not see the whole QR code, reduce the font size of your terminal or increase the window size.
After scanning the QR code the chats should be populated. After you have done this once, whatscli will be able to log into WhatsApp automatically on start. To log out of WhapsApp completely type `/logout`.
### Messaging / Commands
Select a chat on the left and start typing in the input field at the bottom to send messages. Switch between the chat list and the input fiel with `<Tab>`.
For issuing commands the same input field is used. By default commands are prefixed with `/`. You can for example use the `/sendimage /path/to/file.jpg` command to send images, see `/help` for more commands.
When paths are given for commands you don't need to surround the path in quotes, even if it contains spaces. Also don't prefix spaces with backslashes (as the copy-paste function of MacOS does for example).
### Messages
When pressing `Ctrl-w` (default mapping) you enter "message selection mode" which allows selecting a single message and performing operations on them. For example pressing `o` while a message is selected allows opening any attachments through an external application.
#### Image display
You can display images in whatscli using external programs that convert the image to UTF characters. I found that `jp2a` works well for jpeg images, it is available through package managers on most systems. However the "image quality" leaves a lot to be desired. The [PIXterm](https://github.com/eliukblau/pixterm) app allows displaying true-color versions of the images which are quite recognizable already.
To configure the used command and its parameters edit the `show_command` parameter in `whatscli.config`, see `/help` for the config file location.
#### Copy-Pasting User IDs
Some commands such as the `/add` and `/remove` require a "user id" as their input. You can copy the user ID of a selected chat or a selected message to the clipboard with `Ctrl-c` (default mapping) and easily append them to the current input using `Ctrl-v`.
### Notifications
The app supports basic desktop notifications through the `gen2brain/beeep` library, to enable it set `enable_notifications = true` in `whatscli.config`. Set `use_terminal_bell = true` to ring your terminal's bell instead of sending a desktop notification.
### Configuration
Most key bindings, colors and other options can be configured in the `whatscli.config` file, the `/help` command shows its location.
## Development
This app started as my first attempt at writing something in go. Some areas that are marked with `TODO` can still be improved but work mostly. If you want to contribute features or improve the code thats great, send a PR and we can discuss.
@@ -71,3 +111,7 @@ Session manager is designed "object like", the MessageDatabase in `messages/stor
In `messages/messages.go` most interfaces and data structures for communication are kept.
The `config/settings.go` keeps a singleton `Config` struct with the config that is loaded via the gopkg.in/ini.v1 library when the app starts. This makes it easy to quickly add new configuration items with default values that can be used across the app.
## License
This software is released under MIT license. Remember that this gives you all freedom except for slapping your name on it.

View File

@@ -25,7 +25,9 @@ type General struct {
CmdPrefix string
ShowCommand string
EnableNotifications bool
UseTerminalBell bool
NotificationTimeout int64
BacklogMsgQuantity int
}
type Keymap struct {
@@ -76,7 +78,9 @@ var Config = IniFile{
CmdPrefix: "/",
ShowCommand: "jp2a --color",
EnableNotifications: false,
UseTerminalBell: false,
NotificationTimeout: 60,
BacklogMsgQuantity: 10,
},
&Keymap{
SwitchPanels: "Tab",

View File

@@ -17,7 +17,7 @@ import (
"gitlab.com/tslocum/cbind"
)
var VERSION string = "v1.0.5"
var VERSION string = "v1.0.7"
var sndTxt string = ""
var currentReceiver messages.Chat = messages.Chat{}
@@ -427,7 +427,7 @@ func PrintCommands() {
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"quit [::-]or[::b]", config.Config.Keymap.CommandQuit, "[::-] = Exit app")
fmt.Fprintln(textView, "")
fmt.Fprintln(textView, "[-::-]Chat[-::-]")
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"backlog [::-]or[::b]", config.Config.Keymap.CommandBacklog, "[::-] = load next 10 previous messages")
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"backlog [::-]or[::b]", config.Config.Keymap.CommandBacklog, "[::-] = load next", config.Config.General.BacklogMsgQuantity, "previous messages")
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"read [::-]or[::b]", config.Config.Keymap.CommandRead, "[::-] = mark new messages in chat as read")
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"upload[::-] /path/to/file = Upload any file as document")
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"sendimage[::-] /path/to/file = Send image message")

View File

@@ -89,8 +89,8 @@ func (sm *SessionManager) runManager() error {
if int64(msg.Info.Timestamp) > time.Now().Unix()-30 {
if int64(msg.Info.Timestamp) > sm.lastSent.Unix()+config.Config.General.NotificationTimeout {
sm.db.NewUnreadChat(msg.Info.RemoteJid)
if config.Config.General.EnableNotifications && !msg.Info.FromMe {
err := beeep.Notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text, "")
if !msg.Info.FromMe {
err := notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text)
if err != nil {
sm.uiHandler.PrintError(err)
}
@@ -101,8 +101,8 @@ func (sm *SessionManager) runManager() error {
// notify if message is younger than 30 sec and not in focus
if int64(msg.Info.Timestamp) > time.Now().Unix()-30 {
sm.db.NewUnreadChat(msg.Info.RemoteJid)
if config.Config.General.EnableNotifications && !msg.Info.FromMe {
err := beeep.Notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text, "")
if !msg.Info.FromMe {
err := notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text)
if err != nil {
sm.uiHandler.PrintError(err)
}
@@ -279,7 +279,7 @@ func (sm *SessionManager) execCommand(command Command) {
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Unknown command: [-]" + cmd)
case "backlog":
if sm.currentReceiver != "" {
count := 10
count := config.Config.General.BacklogMsgQuantity
if currentMsgs, ok := sm.db.textMessages[sm.currentReceiver]; ok {
if len(currentMsgs) > 0 {
firstMsg := currentMsgs[0]
@@ -985,3 +985,15 @@ func writeSession(session whatsapp.Session) error {
func removeSession() error {
return os.Remove(config.GetSessionFilePath())
}
// notify will send a notification via beeep if EnableNotification is true. If
// UseTerminalBell is true it will send a terminal bell instead.
func notify(title, message string) error {
if !config.Config.General.EnableNotifications {
return nil
} else if config.Config.General.UseTerminalBell {
_, err := fmt.Printf("\a")
return err
}
return beeep.Notify(title, message, "")
}