Skip to content
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

add telegram agent #1381

Merged
merged 3 commits into from Mar 31, 2016
Merged

add telegram agent #1381

merged 3 commits into from Mar 31, 2016

Conversation

tomknig
Copy link
Contributor

@tomknig tomknig commented Mar 27, 2016

Hi, this agent aims to be an alternative to notifications via slack, sms or email. It makes use of the telegram bot api to post values of events via telegram.
The simple case is sending the value of a text field of an event. More interesting is fetching the image behind the url in a photo field of an event and send it to you. This enables you e.g. to check for the latest xkcd and receive the image itself via telegram. The same is true for audio, video and document keys accordingly.

I decided to add the dependency to telegram-bot-ruby since it is a welcome abstraction of the api but more importantly of the multipart uploads that are necessary for the mentioned use of file sendings. As far as I know, the latter could not easily be done with httparty, which already is an dependency, but would at least require another dependency such as httmultiparty. So that's why I thought it's worth including telegram-bot-ruby.

I am happy to get any feedback on my thoughts and the code. Thanks for huginn! :)

@tomknig tomknig changed the title implement basic telegram agent add telegram agent Mar 28, 2016
@cantino
Copy link
Member

cantino commented Mar 29, 2016

Awesome @tomknig, thanks! Do you have any sense how hard it would be to make it work with httparty + httmultiparty?

@tomknig
Copy link
Contributor Author

tomknig commented Mar 29, 2016

I think the sending messages part wouldn't be too hard. Although I look forward to add support for telegram commands, which could be used to partly remote control huginn. Something like sending huginn messages such as /run XKCD Scraper or /get latest .. would be pretty interesting I think. So using the included gem therefore would be pretty handy.
I look into implementing the sending part with httmultiparty, shouldn't be too hard!

@tomknig
Copy link
Contributor Author

tomknig commented Mar 29, 2016

So I migrated the code to httmultiparty, which I now added to the Gemfile explicitly. It was already included as dependency of hypdf which I bumped in the Gemfile to 1.0.10, since it previously locked the version of httmultiparty. Seems legit to me, since it is only a tiny-version upgrade and the test-suite still passes :)

What do you think?

It is assumed that events have either a `text`, `photo`, `audio`, `document` or `video` key. You can use the EventFormattingAgent if your event does not provide these keys.

The value of `text` key is sent as a plain text message.
The value of `photo`, `audio`, `document` and `video` keys should be an url which contents are sent to you according to the type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: maybe "should be a url whose contents will be sent to you".

@cantino
Copy link
Member

cantino commented Mar 30, 2016

Awesome @tomknig!

- minor improvements of the description
- use HTTMultiParty directly, instead of including it
- ensure that tempfiles are closed and unlinked
@tomknig
Copy link
Contributor Author

tomknig commented Mar 30, 2016

Thank you for the valuable feedback, @cantino! I would be happy if you could review the file closing and unlinking.

@cantino
Copy link
Member

cantino commented Mar 31, 2016

Looks great to me, thanks!

@cantino cantino merged commit 85d901b into huginn:master Mar 31, 2016
@Pcsl
Copy link

Pcsl commented Apr 1, 2016

Thanks for your work I love the way Telegram lets you handle bots. It's a really useful intermediate way between instant email and feeds.

I think there is an error in the description:

Obtain your private chat_id from the recently started conversation by visiting https://api.telegram.org/bot/getUpdates

It should be https://api.telegram.org/bot/getUpdates instead (or any other way you think you can state you need to insert there the auth_token.

@tomknig
Copy link
Contributor Author

tomknig commented Apr 1, 2016

Hi @Pcsl, thank you! I think I don't really understand what you mean.
The BotFather will send you the private auth_token of your newly created bot in step 1. To get the updates of that specific bot, you have to visit https://api.telegram.org/bot <auth_token> /getUpdates and replace the <auth_token> with you private auth_token...


1. Obtain an `auth_token` by [creating a new bot](https://telegram.me/botfather).
2. Send a private message to your bot by visiting https://telegram.me/YourHuginnBot
3. Obtain your private `chat_id` from the recently started conversation by visiting https://api.telegram.org/bot<auth_token>/getUpdates
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that is why I was confused. The description contains the auth_token, but markdown seems to omit it! Thank you for reporting that!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was it. Thank you for your hard work!

@tomknig
Copy link
Contributor Author

tomknig commented Apr 1, 2016

I fix that in #1399, thanks @Pcsl!

@jarlave
Copy link

jarlave commented Jul 22, 2016

I have a problem wit this Agent, maybe I don't understand how to use it right.
I added my auth_token and the chat_id @Testtest
now it get an event with this: {"text":"Just a test"}

Is this right? If yes, I don't get messages.

If I try it over my browser with this URL
https://api.telegram.org/bot<auth_token>/sendMessage?chat_id=@testest&text=Testing%20if%20this%20works

get a message, a bit strange.

@tomknig
Copy link
Contributor Author

tomknig commented Jul 22, 2016

Hi @jarlave,

i think the problem is probably the incorrect chat_id. You have to obtain your chat_id from the conversation by visiting https://api.telegram.org/bot<auth_token>/getUpdates. Got to replace <auth_token> with your auth token... Hope that helps!

@jarlave
Copy link

jarlave commented Jul 26, 2016

Ok, thanks, now it works, don't know what I did wron last time, now I need to find out how to make newline because %0A isn't working with this agent.

@tomknig
Copy link
Contributor Author

tomknig commented Jul 26, 2016

👍 you did try \n I guess?

Am 26.07.2016 um 09:45 schrieb jarlave notifications@github.com:

Ok, thanks, now it works, don't know what I did wron last time, now I need to find out how to make newline because %0A isn't working with this agent.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@Pcsl
Copy link

Pcsl commented Jul 26, 2016

\n works for me. Just take into account that when editing the agent for some reason a new slash is added so that can cause problems. Just make sure you are using \n and not \n

@jarlave
Copy link

jarlave commented Jul 26, 2016

I tried both, \n (single slash) and \n (double slash) in the event formating agent to send it to the telegram agent, nothing works, What is wrong.

@dsander
Copy link
Collaborator

dsander commented Jul 26, 2016

@jarlave Does using {% line_break %} in the EventFormattingAgent work?

@jarlave
Copy link

jarlave commented Jul 27, 2016

Yes, this works, thanks to all! That was a tough nut to crack :D

@tomknig
Copy link
Contributor Author

tomknig commented Jul 27, 2016

Cool! And thanks for the support! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants