-
-
Save tdryer/0cf6903eeb3dc948bae0 to your computer and use it in GitHub Desktop.
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
import asyncio | |
import hangups | |
CONVERSATION_ID = 'UgyoEJW1M5TLSnPWY494AaABAQ' | |
MESSAGE = 'hello world' | |
REFRESH_TOKEN_PATH = '/home/tom/.cache/hangups/refresh_token.txt' | |
@asyncio.coroutine | |
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=CONVERSATION_ID | |
), | |
client_generated_id=client.get_client_generated_id(), | |
), | |
message_content=hangups.hangouts_pb2.MessageContent( | |
segment=[hangups.ChatMessageSegment(MESSAGE).serialize()], | |
), | |
) | |
yield from client.send_chat_message(request) | |
yield from client.disconnect() | |
def main(): | |
cookies = hangups.auth.get_auth_stdin(REFRESH_TOKEN_PATH) | |
client = hangups.Client(cookies) | |
client.on_connect.add_observer(lambda: asyncio.async(send_message(client))) | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(client.connect()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment