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:
|
with:
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
build-args: |
|
|
||||||
APP_URL="${{ vars.APP_URL }}"
|
|
||||||
tags: gitea.stuzer.link/stuzer05/monobank-firefly3-bot:latest
|
tags: gitea.stuzer.link/stuzer05/monobank-firefly3-bot:latest
|
||||||
cache-from: type=registry,ref=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
|
cache-to: type=inline
|
@ -1,8 +1,11 @@
|
|||||||
FROM golang:1.23.2 AS builder
|
FROM golang:1.23.2 AS builder
|
||||||
|
|
||||||
|
# Install certificates
|
||||||
|
RUN apt-get update && apt-get install -y ca-certificates
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum .
|
||||||
|
|
||||||
RUN go mod download && go mod verify
|
RUN go mod download && go mod verify
|
||||||
|
|
||||||
@ -14,7 +17,6 @@ RUN make
|
|||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
COPY --from=builder /etc/ssl/* /etc/ssl
|
|
||||||
COPY --from=builder /app/monobank-firefly3-bot /app
|
COPY --from=builder /app/monobank-firefly3-bot /app
|
||||||
|
|
||||||
ENTRYPOINT ["/app"]
|
ENTRYPOINT ["/app"]
|
@ -55,7 +55,7 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// find matching transaction to delete
|
// find matching transaction to adjust/delete
|
||||||
isDeleted := false
|
isDeleted := false
|
||||||
for _, tRows := range oldTransactions.Data {
|
for _, tRows := range oldTransactions.Data {
|
||||||
if isDeleted {
|
if isDeleted {
|
||||||
@ -70,24 +70,54 @@ func ImportTransaction(monobankTransaction monobank.WebHookResponse) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read monobank transaction
|
// read monobank transaction
|
||||||
var monobankTransaction monobank.WebHookResponse
|
var monobankTransactionOld monobank.WebHookResponse
|
||||||
err = json.Unmarshal(notesBytes, &monobankTransaction)
|
err = json.Unmarshal(notesBytes, &monobankTransactionOld)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
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
|
// find transaction
|
||||||
sum := int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.Amount/100))) - int(math.Abs(math.Round(monobankTransaction.Data.StatementItem.CommissionRate/100)))
|
if slices.Contains(row.Names, monobankTransactionOld.Data.StatementItem.Description) {
|
||||||
sum2, _ := strconv.ParseFloat(tRow.Amount, 64)
|
if sumNew == sumOld {
|
||||||
if slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) && sum == int(sum2) {
|
// delete transaction
|
||||||
// delete transaction
|
opts := firefly3.TransactionsApiDeleteTransactionOpts{}
|
||||||
opts := firefly3.TransactionsApiDeleteTransactionOpts{}
|
_, err := App().Firefly3Client.TransactionsApi.DeleteTransaction(context.Background(), tRows.Id, &opts)
|
||||||
_, err := App().Firefly3Client.TransactionsApi.DeleteTransaction(context.Background(), tRows.Id, &opts)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
webhook.go
22
webhook.go
@ -9,6 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
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
|
// read request body bytes
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,14 +40,16 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if transaction hs been logged
|
// only check for logged transaction if not a retry
|
||||||
isTransactionAlreadyLogged, err := app.LogContainsTransactionID(monobankTransaction.Data.StatementItem.Id)
|
if !isRetry {
|
||||||
if err != nil {
|
isTransactionAlreadyLogged, err := app.LogContainsTransactionID(monobankTransaction.Data.StatementItem.Id)
|
||||||
app.LogString(err.Error())
|
if err != nil {
|
||||||
return
|
app.LogString(err.Error())
|
||||||
}
|
return
|
||||||
if isTransactionAlreadyLogged {
|
}
|
||||||
return
|
if isTransactionAlreadyLogged {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = app.ImportTransaction(monobankTransaction)
|
err = app.ImportTransaction(monobankTransaction)
|
||||||
|
Reference in New Issue
Block a user