-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added sendToTelegram in proxy and notifier #232
Open
phillamy
wants to merge
30
commits into
SatoshiPortal:dev
Choose a base branch
from
phillamy:features/telegram
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
21db2fd
Added sendToTelegram in proxy and notifier
phillamy 54d53dc
Removed test keys
phillamy 90ce08a
Added Telegram feature in setup + test on CN start
phillamy fdcd7ef
undo change
phillamy 4ad3840
undo change
phillamy 9a155b9
removed empty line
phillamy d3f11d9
move test in tests directory
phillamy 6ce3bd5
Added TG config to setup
phillamy 66b6788
renamed prompter file notifier
phillamy f2d7fe5
minor fix
phillamy ff55bd4
added comment + modified trace
phillamy 5ae063c
Merge remote-tracking branch 'upstream/dev' into features/telegram
phillamy c4dd86b
fix filename conflict after merge
phillamy b41c840
Removed notifier datapath and added dist/.env
phillamy 29a7551
extra-comma removed
phillamy 1830eed
Merge remote-tracking branch 'upstream/dev' into features/telegram
phillamy 201b498
Added TG config script
phillamy 62d6cf3
Reload configs at the end of TG setup via MQTT
phillamy 0b17292
moved setup scripts in notifier
phillamy fd07ba8
Merge remote-tracking branch 'upstream/dev' into features/telegram
phillamy 2f0ccbb
moved ssetup in notifier
phillamy 5e45952
fix a merge fu
phillamy fa4bf60
Test TG only once
phillamy b94e884
new doc for setting up TG
phillamy f414868
Merge branch 'features/telegram' of github.com:phillamy/cyphernode in…
phillamy d0799cf
wait loop able creation + readLoop in notifier
phillamy d7ae529
Merge remote-tracking branch 'upstream/dev' into features/telegram
phillamy f6459a3
tor config
phillamy 7dffd37
Hooked up TG setup in start.sh
phillamy 165b0c8
TG setup with a nicer look - added colors
phillamy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
.vscode | ||
dist/** | ||
!dist/setup.sh | ||
!dist/sr.sh | ||
!dist/sr.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const chalk = require('chalk'); | ||
|
||
const name = 'notifier'; | ||
|
||
const capitalise = function( txt ) { | ||
return txt.charAt(0).toUpperCase() + txt.substr(1); | ||
}; | ||
|
||
const prefix = function() { | ||
return chalk.green(capitalise(name)+': '); | ||
}; | ||
|
||
const featureCondition = function(props) { | ||
return props.features && props.features.indexOf( 'telegram' ) != -1; | ||
}; | ||
|
||
module.exports = { | ||
name: function() { | ||
return name; | ||
}, | ||
prompts: function( utils ) { | ||
return []; | ||
}, | ||
templates: function( props ) { | ||
return [ 'notifier.env' ]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Telegram integration in Cyphernode. | ||
|
||
Build and setup Cyphernode - Choose to enable Telegram. The first time you run Cyphernode, you will get an error concerning Telegram beacause Telegram has to be setup with the next few steps. | ||
|
||
START CYPHERNODE running /dist/start.sh | ||
|
||
In directory cyphernode/notifier_docker/scripts, you will find the script start-tg-setup.sh to start the Telegram setup. It runs inside the notifier container with this command : | ||
docker exec -it $(docker ps -q -f "name=cyphernode_notifier") ./tgsetup.sh | ||
|
||
Follow the steps of the installer - example output follows: | ||
|
||
notifier_docker/script % ./start-tg-setup.sh | ||
Testing database before starting the configuration | ||
Database is alive | ||
Do you wish to configure Telegram for Cyphernode? [yn] yAdding the Telegram base URL in database config table cyphernode_props | ||
[sql] psql -qAtX -h postgres -U cyphernode -c "INSERT INTO cyphernode_props (category, property, value) VALUES ('notifier', 'tg_base_url', 'https://api.telegram.org/bot') ON CONFLICT (category, property) DO NOTHING" | ||
0 | ||
|
||
Please go into your Telegram App and start chatting with the @BotFather | ||
|
||
==> (Step 1) Enter @Botfather in the search tab and choose this bot | ||
==> Note, official Telegram bots have a blue checkmark beside their name | ||
==> (Step 2) Click “Start” to activate BotFather bot. In response, you receive a list of commands to manage bots | ||
==> (Step 3) Choose or type the /newbot command and send it | ||
==> @BotFather replies: Alright, a new bot. How are we going to call it? Please choose a name for your bot | ||
==> (Step 4) Choose a name for your bot. And choose a username for your bot — the bot can be found by its username in searches. The username must be unique and end with the word 'bot' | ||
==> After you choose a suitable name for your bot — the bot is created. You will receive a message with a link to your bot t.me/<bot_username> | ||
==> Cyphernode needs the generated token to access the API: Copy the line below following the message 'Use this token to access the HTTP API' | ||
Enter the token here: 5172851233:AAHkpd4T1ILyhXyqDelNnOTgFE4hl-AQSVMTelegram Setup will now try to obtain the chat ID from the Telgram server. | ||
To make this happen, please go into the Telegram App and send a message to the new bot | ||
Click on the link in the @BotFather's answer : Congratulations on your new bot. You will find it at t.me/your-new-bot. | ||
Trying to contact Telegram server... | ||
[sql] psql -qAtX -h postgres -U cyphernode -c "INSERT INTO cyphernode_props (category, property, value) VALUES ('notifier', 'tg_api_key', '3172855133:AAHkpd4T1ILyhXyqDelNnOTgFE4hl-AQSVM') ON CONFLICT (category, property) DO UPDATE SET value='5182851733:AAHkpd4T1ILyhXyqDelNnOTgFE4hl-AQSVM'" | ||
0 | ||
[sql] psql -qAtX -h postgres -U cyphernode -c "INSERT INTO cyphernode_props (category, property, value) VALUES ('notifier', 'tg_chat_id', '1649436203') ON CONFLICT (category, property) DO UPDATE SET value=1609936104" | ||
0 | ||
|
||
Reloading configs | ||
|
||
Sending message to Telegram [Tue May 3 16:29:03 UTC 2022] | ||
Ok. Done. | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
How it works : | ||
|
||
calling Telegram API | ||
example : | ||
https://api.telegram.org/bot+TELEGRAM_API_KEY/your-action | ||
https://api.telegram.org/botTELEGRAM_API_KEY/getMe | ||
returns: | ||
{"ok":true,"result":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot","can_join_groups":true,"can_read_all_group_messages":false,"supports_inline_queries":false}} | ||
|
||
Add your Bot to a group and then get updates to get the chat.ID in order to send messages to this group afterwards. | ||
Below, the chat.id is chat.id:-TELEGRAM_CHAT_ID | ||
|
||
https://api.telegram.org/botTELEGRAM_API_KEY/getUpdates | ||
|
||
{"ok":true,"result":[{"update_id":701180871, | ||
#"my_chat_member":{"chat":{"id":-TELEGRAM_CHAT_ID,"title":"Logging","type":"group","all_members_are_administrators":false},"from":{"id":1609436204,"is_bot":false,"first_name":"Roger","last_name":"Brulotte","username":"RogerBrulotte","language_code":"en"},"date":1635877254,"old_chat_member":{"user":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"},"status":"member"},"new_chat_member":{"user":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"},"status":"left"}}},{"update_id":701180872, | ||
#"message":{"message_id":7,"from":{"id":1609436204,"is_bot":false,"first_name":"Roger","last_name":"Brulotte","username":"RogerBrulotte","language_code":"en"},"chat":{"id":-TELEGRAM_CHAT_ID,"title":"Logging","type":"group","all_members_are_administrators":true},"date":1635877254,"left_chat_participant":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"},"left_chat_member":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"}}},{"update_id":701180873, | ||
#"my_chat_member":{"chat":{"id":-TELEGRAM_CHAT_ID,"title":"Logging","type":"group","all_members_are_administrators":true},"from":{"id":1609436204,"is_bot":false,"first_name":"Roger","last_name":"Brulotte","username":"RogerBrulotte","language_code":"en"},"date":1635877290,"old_chat_member":{"user":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"},"status":"left"},"new_chat_member":{"user":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"},"status":"member"}}},{"update_id":701180874, | ||
#"message":{"message_id":8,"from":{"id":1609436204,"is_bot":false,"first_name":"Roger","last_name":"Brulotte","username":"RogerBrulotte","language_code":"en"},"chat":{"id":-TELEGRAM_CHAT_ID,"title":"Logging","type":"group","all_members_are_administrators":true},"date":1635877290,"new_chat_participant":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"},"new_chat_member":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"},"new_chat_members":[{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"}]}}]} | ||
|
||
Bot says Hello World using the chat id returned previously | ||
https://api.telegram.org/botTOKEN/sendMessage?chat_id=CHAT-ID&text=Hello+World | ||
https://api.telegram.org/botTELEGRAM_API_KEY/sendMessage?chat_id=-TELEGRAM_CHAT_ID&text=Hello+World | ||
|
||
returns: | ||
{"ok":true,"result":{"message_id":9,"from":{"id":2084591315,"is_bot":true,"first_name":"Roger-logger","username":"RogerLoggerBot"},"chat":{"id":-TELEGRAM_CHAT_ID,"title":"Logging","type":"group","all_members_are_administrators":true},"date":1635877783,"text":"Hello World"}} | ||
|
||
|
||
|
||
curl POST example | ||
curl -X POST https://api.telegram.org/botTELEGRAM_API_KEY/sendMessage?chat_id=TELEGRAM_CHAT_ID -H 'Content-Type: application/json' -d '{"text":"text in POST data"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for pgpass? Let's only mount that specific file... and not in /proxy/db but something more relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Will do