Skip to content

Commit

Permalink
Merge pull request #23 from cyxou/menu-plugin
Browse files Browse the repository at this point in the history
Refactor to using @grammyjs/menu plugin
  • Loading branch information
cyxou authored Nov 5, 2023
2 parents f189753 + dbbb925 commit 082a1cf
Show file tree
Hide file tree
Showing 293 changed files with 9,182 additions and 4,349 deletions.
7 changes: 4 additions & 3 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ BOT_TOKEN=
FIREFLY_URL=

# FIREFLY_API_URL usually can be left blank in which case it will fall back
# to FIREFLY_URL value. But if tou are running this bot in Kubernetes where your
# Firefly server is running, than you must specify the inner Firefly service URL in
# order for the bot be able to access Firefly API, i.e. http://firefly-iii:8080
# to FIREFLY_URL plus an /api subpath value. But if you are running this bot in
# Kubernetes where your Firefly server is running, then you must specify the
# inner Firefly service URL in order for the bot be able to access
# Firefly API, i.e. http://firefly-iii:8080/api
FIREFLY_API_URL=
19 changes: 19 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ env:
DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
GITHUB_REPO: cyxou/firefly-iii-telegram-bot
PR_NUMBER: pr-${{ github.event.number }}
FORCE_COLOR: 1

jobs:
validate_pr:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU for multiplatform builds
id: qemu
uses: docker/setup-qemu-action@v2
with:
image: tonistiigi/binfmt:latest
platforms: all

- uses: actions/checkout@v3

- name: Put back the git branch into git (Earthly uses it for tagging)
Expand All @@ -37,3 +45,14 @@ jobs:
--DOCKERHUB_REPO=$GITHUB_REPO \
--DOCKERHUB_USERNAME=$DOCKERHUB_USERNAME \
--DOCKERHUB_ACCESS_TOKEN=$DOCKERHUB_TOKEN
- name: Docker Login
run: docker login --username $DOCKERHUB_USERNAME --password $DOCKERHUB_TOKEN

- name: Build PR Image
run: |
earthly --ci --push +build-and-push \
--DOCKERHUB_REPO=$GITHUB_REPO \
--DOCKERHUB_USERNAME=$DOCKERHUB_USERNAME \
--DOCKERHUB_ACCESS_TOKEN=$DOCKERHUB_TOKEN \
--RELEASE_VERSION=$PR_NUMBER
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ jobs:
password: ${{ env.DOCKERHUB_TOKEN }}
repository: ${{ env.GITHUB_REPO }}
short-description: ${{ github.event.repository.description }}

- name: Send telegram message on release
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_GROUP_ID }}
token: ${{ secrets.TELEGRAM_RELEASE_NOTIFIER_BOT_TOKEN }}
message: |
🚀 A new release has been published: ${GITHUB_REF:10}
${{ github.event.repository.description }}
3 changes: 3 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ build-and-release:
BUILD --platform=linux/amd64 --platform=linux/arm +buildImage
BUILD +release

build-and-push:
BUILD --platform=linux/amd64 --platform=linux/arm +buildImage

validatePR:
BUILD +runTests
BUILD +buildDist
Expand Down
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@ This Telegram bot facilitates creating [Firefly III](https://www.firefly-iii.org
as well as provides some capabilities to manage other Firefly's entities like
Accounts, Categories, Reports, etc.

<h1 align="center"><img src="https://github.com/cyxou/firefly-iii-telegram-bot/blob/master/assets/welcome-screen.png?raw=true" alt="screenshot" align="center"/></h1>
<h1 align="center"><img src="https://github.com/cyxou/firefly-iii-telegram-bot/blob/master/assets/bot-v2.jpeg?raw=true" alt="screenshot" align="center"/></h1>

## ⚠ Notice: Limited Firefly III Version Support

This Telegram bot is developed for use with Firefly III finance manager.
However, due to time constraints, the support for different Firefly III versions
may be limited.

Please be aware that I may not be able to promptly address issues or developments
related to all Firefly III versions. Users are encouraged to consider this while
using the bot with different versions of Firefly III.

Your understanding and cooperation are appreciated. For the best experience,
it's recommended to use this bot with supported Firefly III versions.

### Version Compatibility

- Version v2 of this bot has been tested with Firefly III v6.0.30.
- All other versions of Firefly III might not work properly with this bot.

Thank you for your understanding.


## Setup
First you'll have to [generate a Telegram Bot token through BotFather](https://core.telegram.org/bots/tutorial#obtain-your-bot-token). Once you generate the token, keep it safe.
Expand All @@ -18,10 +39,9 @@ docker run \
cyxou/firefly-iii-telegram-bot:latest
```

You may also provide additional environment variables via the _.env_ file.
For this rename the _example.env_ to _.env_ and update it with your values.
Then you can pass it to docker like so:

You may also provide BOT_TOKEN via the .env file. For this just rename the
_example.env_ file to _.env_ and update it with your values. Then you can pass it
to docker like so:
```shell
docker run \
--rm --it --init --name firefly-bot \
Expand All @@ -30,6 +50,10 @@ docker run \
cyxou/firefly-iii-telegram-bot:latest
```

Once the bot is running, navigate to its **Settings** and provide all the
necessary information to connect it to your Firefly III instance.


### Manual

For this you need to have NodeJS installed.
Expand Down Expand Up @@ -58,6 +82,7 @@ docker stop earthly-buildkitd || true
```
More info [here](https://docs.earthly.dev/docs/guides/multi-platform).


## TODO
- [x] Add English translations and make it a default language
- [x] Add transactions improvements (create transfers and deposits)
Expand All @@ -70,10 +95,10 @@ More info [here](https://docs.earthly.dev/docs/guides/multi-platform).
- [x] Configure CI/CD so that it builds and pushes docker images on merges to master
- [ ] Reports
- [ ] Proper error handling
- [ ] Tests
- [ ] Firefly API tests
- [x] Add JSON database for persistance (used @grammyjs/storage-file)
- [ ] Add date picker when editing transaction (adopt https://github.com/gianlucaparadise/telegraf-calendar-telegram)
- [ ] Migrate from home grown Mapper to Grammy's Menu plugin
- [0] Migrate from home grown Mapper to Grammy's Menu plugin (partially done)

## Open API Code Generation

Expand Down Expand Up @@ -105,10 +130,11 @@ which is hard-coded in `codegen` npm task.
created upon first creation of a transaction via the Firefly UI. Until that
built-in "(cash)" account is created, the default Expense account will be an
account without a name which is weird.
- Do not try to edit multiple transactions at once, because of the shared state of
the transaction under edit. Doing so will result in unexpected behavior.

## Feedback
Join the 🔗 [Q&A Telegram group](https://t.me/firefly_iii_telegram_bot_group) if you have
any questions, feedback or ideas to implement.
Join our Telegram group: <a class="VPSocialLink" href="https://t.me/firefly_iii_telegram_bot_group" target="_blank" ><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Telegram</title><path d="M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"></path></svg></a>

## License

Expand Down
Binary file added assets/bot-v2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 39 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "firefly-iii-telegram-bot",
"description": "A Telegram bot for working with Firefly III with a supersonic speed",
"version": "1.2.0",
"version": "2.0.0",
"homepage": "https://github.com/cyxou/firefly-iii-telegram-bot#readme",
"license": "GPL-3.0-or-later",
"repository": {
Expand All @@ -23,7 +23,7 @@
"clean:api": "rm -rf src/lib/firefly/api",
"clean:model": "ls ./src/lib/firefly/model/ | grep -v currency-update.ts | xargs -I {} rm ./src/lib/firefly/model/{}",
"precodegen": "npm run clean:api && npm run clean:model",
"codegen": "openapi-generator-cli generate -i https://api-docs.firefly-iii.org/firefly-iii-1.5.6.yaml -o src/lib/firefly -g typescript-axios -c .openapi-generator-config.yaml"
"codegen": "openapi-generator-cli generate -i https://api-docs.firefly-iii.org/firefly-iii-2.0.10-v1.yaml -o src/lib/firefly -g typescript-axios -c .openapi-generator-config.yaml"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.5.2",
Expand All @@ -41,14 +41,14 @@
},
"dependencies": {
"@grammyjs/i18n": "0.5.1",
"@grammyjs/menu": "1.1.2",
"@grammyjs/menu": "1.2.1",
"@grammyjs/router": "2.0.0",
"@grammyjs/storage-file": "2.1.0",
"@grammyjs/storage-file": "2.3.2",
"axios": "1.2.6",
"dayjs": "1.11.7",
"debug": "4.3.4",
"dotenv": "16.0.3",
"grammy": "1.13.1",
"grammy": "1.19.0",
"lodash.curry": "4.1.1",
"lodash.flatten": "4.4.0",
"lodash.isempty": "4.4.0",
Expand Down
9 changes: 6 additions & 3 deletions src/composers/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
} from './helpers'

import firefly from '../lib/firefly'
import { handleCallbackQueryError } from '../lib/errorHandler'
import { AccountTypeFilter } from '../lib/firefly/model/account-type-filter'
import { AccountRead } from '../lib/firefly/model/account-read'
import { ACCOUNTS_PAGE_LIMIT } from './constants'

const debug = Debug(`bot:accounts`)

Expand All @@ -22,6 +24,7 @@ const bot = new Composer<MyContext>()
// List transactions
bot.hears(i18n.t('en', 'labels.ACCOUNTS'), showAccounts)
bot.hears(i18n.t('ru', 'labels.ACCOUNTS'), showAccounts)
bot.hears(i18n.t('it', 'labels.ACCOUNTS'), showAccounts)
bot.callbackQuery(mapper.list.regex(), showAccounts)
bot.callbackQuery(mapper.close.regex(), closeHandler)

Expand Down Expand Up @@ -51,7 +54,7 @@ async function showAccounts(ctx: MyContext) {
log('accType: %O', accType)

const accounts = (await firefly(userSettings).Accounts.listAccount(
page, balanceToDate, accType as AccountTypeFilter)).data.data
undefined, ACCOUNTS_PAGE_LIMIT, page, balanceToDate, accType as AccountTypeFilter)).data.data
log('accounts: %O', accounts)

const keyboard = createAccountsMenuKeyboard(ctx, accType as AccountTypeFilter)
Expand All @@ -68,8 +71,8 @@ async function showAccounts(ctx: MyContext) {
reply_markup: keyboard
})
}
} catch (err) {
console.error(err)
} catch (err: any) {
return handleCallbackQueryError(err, ctx)
}
}

Expand Down
Loading

0 comments on commit 082a1cf

Please sign in to comment.