Should be doable with Termux:
- https://f-droid.org/packages/com.termux (the terminal emulator itself);
- https://f-droid.org/packages/com.termux.api (for
termux-sms-listandtermux-sms-sendcommands); - https://f-droid.org/packages/com.termux.boot (to make the script launch automatically after reboots; don't forget a wake lock to keep the process alive).
termux-sms-list returns messages in JSON, which is easy enough to handle with, say, jq in bash or json in python. The script itself can be a simple loop that fetches the latest messages every few minutes, filters for unprocessed ones from whitelisted numbers and calls termux-sms-send.
Maybe it'd make sense to daemonise the script and launch it via sv.
But the Termux app weighs quite a bit itself.