IMPROVEMENT: updated the connector to process-telegram-updates. new version allows telegram to know available commands

This commit is contained in:
Frederico @ VilaRosa02 2025-08-31 18:00:58 +00:00
parent cc2af6c1ca
commit bf1566e6a0

View File

@ -1,7 +1,7 @@
.SECONDARY: .SECONDARY:
SHELL=/bin/bash -x SHELL=/bin/bash
ROOT_DIR=/mnt/servers/aws.fredericofalcao.com/api.fredericofalcao.com/data/emails ROOT_DIR=/mnt/servers/aws.fredericofalcao.com/api.fredericofalcao.com/data/emails
#SRC_EML_FILES=$(notdir $(shell find "$(ROOT_DIR)" -type f -name "*.eml" | head -n 2)) #SRC_EML_FILES=$(notdir $(shell find "$(ROOT_DIR)" -type f -name "*.eml" | head -n 2))
LATEST_FILE:=$(shell find "$(ROOT_DIR)" -name "*.eml" -printf '%T@ %p\n' | sort -n | tail -1) LATEST_FILE:=$(shell find "$(ROOT_DIR)" -name "*.eml" -printf '%T@ %p\n' | sort -n | tail -1)
@ -16,17 +16,20 @@ SRC_FILES=$(subst .score.txt,.notification.txt,$(SRC_SCORE_FILES))
all: $(SRC_FILES) all: $(SRC_FILES)
# 8. Upload telegram available bot commands
upload-available-bot-commands: ../process-telegram-updates/commands/01_learn.inc.php ../process-telegram-updates/commands/02_memory.inc.php
cd ../process-telegram-updates && make upload-available-commands
# 7. Processed received messages # 7. Processed received messages
process-telegram-updates: ../process-telegram-updates/process_message.php process-telegram-updates: ../process-telegram-updates/commands/01_learn.inc.php ../process-telegram-updates/commands/02_memory.inc.php
cd ../process-telegram-updates && make cd ../process-telegram-updates && make
../process-telegram-updates/process_message.php: ../process-telegram-updates/commands/02_memory.inc.php: .dummy
printf '%s\n' \ echo '<?php return ["command"=>"/memories","description"=>"list all the memories","callback"=>function($$from,$$chat,$$date,$$text){telegram_send_text($$chat["id"],file_get_contents(__DIR__."/../data/learnings.txt"));}];' > $@
'<?php function process_message(array $$from,array $$chat,string $$date,string $$text) { '\
' if (substr($$text,0,7) == "/learn ") file_put_contents(__DIR__."/data/learnings.txt", substr($$text,7)."\n",FILE_APPEND); '\ ../process-telegram-updates/commands/01_learn.inc.php: .dummy
' if (substr($$text,0,7) == "/memory") telegram_send_text($$chat["id"],file_get_contents(__DIR__."/data/learnings.txt"));'\ echo '<?php return ["command"=>"/learn","description"=>"learn a new instruction","callback"=>function($$from,$$chat,$$date,$$text){file_put_contents(__DIR__."/../data/learnings.txt", substr($$text,7)."\n",FILE_APPEND);}];' > $@
' }' > $@
# 6. Run the MAIL-ROUTE script to either notify the user of a new message, or ignore # 6. Run the MAIL-ROUTE script to either notify the user of a new message, or ignore
@ -78,7 +81,7 @@ telegram_notification.log: email_message.eml
-F caption="Here is your file 📎" \ -F caption="Here is your file 📎" \
-F document="@$<" > $@ -F document="@$<" > $@
.dummy:
clean: clean:
rm *.sys *.txt *.log *.eml rm *.sys *.txt *.log *.eml