You've already forked monobank-firefly3-bot
Compare commits
10 Commits
39459202f1
...
master
Author | SHA1 | Date | |
---|---|---|---|
a5c9403576
|
|||
ebb213a3cc
|
|||
f947606131
|
|||
464093e5bd
|
|||
f96f88d16e
|
|||
686c46bf78
|
|||
38b4e89a02
|
|||
3986e1c9de
|
|||
f0e26a0cd2
|
|||
00657a8660
|
@ -29,8 +29,6 @@ jobs:
|
||||
with:
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
build-args: |
|
||||
APP_URL="${{ vars.APP_URL }}"
|
||||
tags: gitea.stuzer.link/stuzer05/monobank-firefly3-bot:latest
|
||||
cache-from: type=registry,ref=gitea.stuzer.link/stuzer05/monobank-firefly3-bot:latest
|
||||
cache-to: type=inline
|
@ -1,8 +1,11 @@
|
||||
FROM golang:1.23.2 AS builder
|
||||
|
||||
# Install certificates
|
||||
RUN apt-get update && apt-get install -y ca-certificates
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY go.mod go.sum ./
|
||||
COPY go.mod go.sum .
|
||||
|
||||
RUN go mod download && go mod verify
|
||||
|
||||
@ -14,7 +17,6 @@ RUN make
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=builder /etc/ssl/* /etc/ssl
|
||||
COPY --from=builder /app/monobank-firefly3-bot /app
|
||||
|
||||
ENTRYPOINT ["/app"]
|
@ -55,7 +55,7 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// find matching transaction to delete
|
||||
// find matching transaction to adjust/delete
|
||||
isDeleted := false
|
||||
for _, tRows := range oldTransactions.Data {
|
||||
if isDeleted {
|
||||
@ -70,24 +70,54 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
||||
}
|
||||
|
||||
// read monobank transaction
|
||||
var monobankTransaction monobank.WebHookResponse
|
||||
err = json.Unmarshal(notesBytes, &monobankTransaction)
|
||||
var monobankTransactionOld monobank.WebHookResponse
|
||||
err = json.Unmarshal(notesBytes, &monobankTransactionOld)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse amounts
|
||||
sumNew := int64(math.Abs(math.Round(monobankTransaction.Data.StatementItem.Amount/100))) - int64(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate/100)))
|
||||
sumOldFloat, _ := strconv.ParseFloat(tRow.Amount, 64)
|
||||
sumOld := int64(sumOldFloat)
|
||||
|
||||
// find transaction
|
||||
sum := int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.Amount/100))) - int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate/100)))
|
||||
sum2, _ := strconv.ParseFloat(tRow.Amount, 64)
|
||||
if slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) && sum == int(sum2) {
|
||||
if slices.Contains(row.Names, monobankTransactionOld.Data.StatementItem.Description) {
|
||||
if sumNew == sumOld {
|
||||
// delete transaction
|
||||
opts := firefly3.TransactionsApiDeleteTransactionOpts{}
|
||||
_, err := App().Firefly3Client.TransactionsApi.DeleteTransaction(context.Background(), tRows.Id, &opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// adjust transaction
|
||||
opts := firefly3.TransactionsApiUpdateTransactionOpts{}
|
||||
body := firefly3.TransactionUpdate{
|
||||
Transactions: []firefly3.TransactionSplitUpdate{
|
||||
{
|
||||
Description: tRow.Description,
|
||||
CategoryId: tRow.CategoryId,
|
||||
DestinationId: tRow.DestinationId,
|
||||
SourceId: tRow.SourceId,
|
||||
CurrencyId: tRow.CurrencyId,
|
||||
ExternalUrl: tRow.ExternalUrl,
|
||||
Date: tRow.Date,
|
||||
DueDate: tRow.DueDate,
|
||||
Tags: tRow.Tags,
|
||||
Notes: tRow.Notes,
|
||||
// Notes: string(monobankTransactionJson),
|
||||
Amount: strconv.FormatInt(sumOld-sumNew, 10),
|
||||
},
|
||||
},
|
||||
}
|
||||
_, _, err := App().Firefly3Client.TransactionsApi.UpdateTransaction(context.Background(), body, tRows.Id, &opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
isDeleted = true
|
||||
isDeleted = true // break 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
// Parse URL query parameters
|
||||
queryParams := r.URL.Query()
|
||||
isRetry := queryParams.Get("retry") == "true"
|
||||
|
||||
// read request body bytes
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
@ -36,7 +40,8 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// check if transaction hs been logged
|
||||
// only check for logged transaction if not a retry
|
||||
if !isRetry {
|
||||
isTransactionAlreadyLogged, err := app.LogContainsTransactionID(monobankTransaction.Data.StatementItem.Id)
|
||||
if err != nil {
|
||||
app.LogString(err.Error())
|
||||
@ -45,6 +50,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
if isTransactionAlreadyLogged {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = app.ImportTransaction(monobankTransaction)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user