-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a `start-bot` command, which connects to WhatsApp and allows executing a few commands: - `!psr` to get an updated summary of the SAMU activities of tomorrow - `!bspp` to get the current summary of the BSPP activities of tomorrow
- Loading branch information
1 parent
a7316d4
commit f60bf7e
Showing
5 changed files
with
241 additions
and
58 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fabien-chebel/pegass-cli/whatsapp" | ||
log "github.com/sirupsen/logrus" | ||
"go.mau.fi/whatsmeow/types" | ||
"time" | ||
) | ||
|
||
type BotService struct { | ||
pegassClient *PegassClient | ||
chatClient *whatsapp.WhatsAppClient | ||
} | ||
|
||
func (b *BotService) SendActivitySummary(recipient types.JID, kind ActivityKind) { | ||
|
||
err := b.chatClient.SendMessage("🤖 C'est reçu. Je génère l'état des postes de demain.", recipient) | ||
if err != nil { | ||
log.Errorf("failed to send whatsapp message: %s", err.Error()) | ||
return | ||
} | ||
|
||
day := time.Now().AddDate(0, 0, 1).Format("2006-01-02") | ||
log.Info("Fetching activity summary for day ", day) | ||
summary, err := b.pegassClient.GetActivityOnDay(day, kind) | ||
if err != nil { | ||
log.Errorf("failed to generate activity summary for day '%s' and kind '%d'", day, kind) | ||
return | ||
} | ||
summary = fmt.Sprintf("Etat du réseau de secours de demain (%s):\n%s", day, summary) | ||
|
||
err = b.chatClient.SendMessage( | ||
summary, | ||
recipient, | ||
) | ||
} |
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
Oops, something went wrong.