-
Notifications
You must be signed in to change notification settings - Fork 189
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
How to use the send_message.py code within another code? #415
Comments
whats the error when you try to run it this way? |
I got the following error 👍
it always complain about the arguments so i am not sure how to pass them inside a script. |
The example code defines script command arguments; it doesn't send the actual conversation ID because that's read from the argument list (i.e. as given from your shell) as per If you're interacting with hangups from another script then don't go via the examples -- they're exactly that: simple examples under an independent wrapper. You should work with the client directly, which means creating a client, adding a handler for async def callback():
# Do your tasks here.
client = hangups.Client(...)
client.on_connect.add_observer(callback)
loop = asyncio.get_event_loop()
task = asyncio.ensure_future(client.connect(), loop=loop)
try:
loop.run_until_complete(task)
except KeyboardInterrupt:
task.cancel()
loop.run_until_complete(task)
finally:
loop.close() |
OllieTerrance, thanks for the response but i am too new to python so i am not sure were to go from there but thanks that will help others with better knowledge. |
is there any chance you could create a quick sample to send msg? i am using 'import os' to run the send_message.py and this is taking alot of resources, i am running PI3B with Opencv with MobileNet SSD neural network and sending screenshot results through hangups works great but pi is to resource limited. |
masterchop, can you please share the code of sending sms (of your work).. |
I am not doing anything special, i am just importing the os module and do a system command:
But this code probably creates a session everytime and i would like to have the session open like the chat client. |
ok |
I have the same question. I am really new to python and would like an example of a basic .py that would simply repeat the received text to the sender. I would then be able to work from there. |
tritto |
@Synoptic2 Same here |
Then this probably isn't a good place for you to start off. Working with hangups directly requires knowledge of using the asyncio module correctly, which itself requires a strong understanding of Python. You should make yourself familiar with the language (and programming in general, if applicable) -- this guide lists plenty of places to make a start. From there, you should learn how to make a simple asyncio program before continuing. The docs cover all the details, but it's not the easiest thing to pick up from there -- a tutorial like this one may be easier to digest. At that point you should be able to take the sample code above and adjust the callback to your needs, or wrap it up into something a bit more usable. Note that the client here isn't really suited for one-shot style invocation, as there's a lot of startup overhead -- ideally you would have a long-running client along with a way to pass messages into a running instance. |
This my code; this function is called when a certain button is selected using urwid item_chosen() and is passed these params (conversation.id_ , 'lorem ipusm')
|
@masterchop is this still an issue for you? Did you get this to work for your home security system? |
It seems a few people want to use hangups as part of a bigger project - perhaps as part of a notification system for home security for example. I had many issues initially trying to get hangups to work, but I did have some success in the end. I agree with the statement above comment about asyncio. You really need to understand how it works to get a better overall understanding of the workings of hangups itself. I'm not quote there myself, but have managed to fumble my way through. I have extracted the code that I use from my home security program that sends messages to my phone every time a person is detected on the camera at the front door. I hope that it will be useful for a few of you. The code provides a basic function to send a hangouts message and then 2 scenarios. 1 with an image and 1 without.
I hope this is useful to someone. |
dude, i have been waiting for this for while, how do i use it. Please tell me how to use it! |
Hi, Everything I have learned in Python is through research & review of other peoples code, but I honestly believe I have learned more through my own mistakes (and fixing them) than anyone simply giving me the code and telling me how to use it. I'd suggest you run it first and look at any errors to understand what you might be missing. Its only my opinion, but you really need to understand it yourself to make sense of it. I've found looking at other peoples code to be helpful in making a start, but you will need to do some research here first yourself to truly understand what you are looking at here. |
Yes, i understand what you are saying for the variables but wont this one disconnects from the session too? |
Yes, it could send multiple messages - given it is incorporated into your own code properly. I can read the message on my phone. I guess I could respond. This code is out of a program for finding people in a security camera. There is a counter - once the counter hits a certain number, it sends a message and a picture - in both hangouts and to my gmail account. The counter resets and then will alarm again if the counter hits that number. It works, but is not without its bugs that I need to fix. The code I have provided simply shows how to send a message in hangouts using hangups. You can use it as an example and incorporate it into your own code to send as many messages as you want to as many people as you want or to a group chat. All you need to do is take the functions and call them as necessary. Its fair to say its not simple to do, but again, once you understand the code, you can send messages at will. If you want to set up some sort of security system as your first post advises, then this is but a very small snippet of code in a much larger more complex program. The code I provided is from my project probably doing something similar to what I presume you are trying to achieve...
This is what I see in hangouts sent from the program. The code I provided is responsible for getting that information into hangouts. |
yes. something like that. My main goal is to have the hangups as a chatbot that i can write back and forward. I can request updates and stuff without port forwarding. I tell him to do stuff inside my network like patterns of activity when noone is home. i had it ready with my crappy workaround but unfortunately it disconnected to much been inconsistent and i had to switch to SMTP emails. Ill give it a go to your code and see if this works as expected. Thanks for sharing :) |
I am not able to send images, i get the following error:
The message does arrived and i make sure the image existed, i also replace the image with None to see if i could just send a txt msg but that hang too. |
Hmm, Are you just using the code provided above? |
I got the text msg, then the error and terminal hang. |
yeah you don't need that. Whats is the image that you are trying to send? |
I tried wit ha PNG and a JPEG file both with the same result. PATH: /home/chop/Scripts/images/2.jpeg The path is the home folder of the user executing the script. |
Hmm, I can't replicate that issue here. |
That conversation id works on the send_message.py sample |
Not sure there is anything else I can do to help you here. The code I provided works for me - I can send message after message without any issue with or without an image. You might want to do some research on |
I really appreciate your help @IamSierraCharlie , thank you I've read multiple threads in asyncio and I know roughly how it works but it's still a new concept for me |
what version of python are you running? I have that code running on 3.6.3 |
3.7.2 I'll try to make a new env a run it again |
Do you us an IDE - like pycharm? |
vs code |
so is it the IDE complaining about invalid syntax? or do you see an error when you attempt to run the code? |
yes |
@IamSierraCharlie |
okay - great to see you are moving along a little. I think its fair to say that hangups is particular about modules that are installed. Do you know what version of hangups you are running? Did you install it using pip or did you build it from source? Could you tell me your process? I'll try and replicate your setup here. To be honest, I set this up a while back and I probably need to go through it again myself so why not follow your setup process and see if I end up with the same issue. What I can tell you is that my IDE complains about async reference missing from asyncio, but it still works |
I used the github source cloning then |
hmm okay. I used pip and run hangups 0.4.6 (0.4.4) also works. Was there an open issue for manual login not working? What is the motive for using this? I'll try build this from source and see if I get the same result - standby |
my installed hangups version is 0.4.6 |
Okay, I created a new environment (using anaconda) in Ubuntu 16.04 using python 3.6.3 and I've just built from source and it works fine. What can you tell me about your asynchio module? What version is it? Just to be certain, you are running this in Linux or MAC OS? |
So I made a new conda env on Ubuntu 18.04.1 LTS and using python=3.6.3 and installing hangups using pip this time in that env |
Glad that it is working for you. |
It was easier to move to telegram. Simple api if Hangouts is not mandatory |
Hello i have been using this software alot for my home security system but i have struggle with the send_message.py script i cant figure out how to use it in another code.
i tried using its code on the interactive shell:
` import hangups
from common import run_example
async def send_message(client):
request = hangups.hangouts_pb2.SendChatMessageRequest(
request_header=client.get_request_header(),
event_request_header=hangups.hangouts_pb2.EventRequestHeader(
conversation_id=hangups.hangouts_pb2.ConversationId(
id="Ugz1TPwdoBnYwNq9RXN4AaABAagB-YGbAQ"
),
client_generated_id=client.get_client_generated_id(),
),
message_content=hangups.hangouts_pb2.MessageContent(
segment=[
hangups.ChatMessageSegment("Test").serialize()
],
),
)
await client.send_chat_message(request)`
But i am not able to call it to send a message i have tried all this sequenses:
` run_example(send_message, '--conversation-id Ugz1TPwdoBn9RXN4AaABAagB-YGbAQ', '--message-text hola')
run_example(send_message, '--conversation-id', 'Ugz1TPwdoBnq9RXN4AaABAagB-YGbAQ', '--message-text', 'hola')
run_example(send_message, '--conversation-id:Ugz1TPwdoBNq9RXN4AaABAagB-YGbAQ', '--message-text:hola')
run_example(send_message, 'Ugz1TPwdoBnq9R4AaABAagB-YGbAQ', 'hola')`
Any help is welcome
The text was updated successfully, but these errors were encountered: