Ejemplo n.º 1
0
def getpub(threema_id, threema_api_secret, requested_id):
    connection = Connection(threema_id, threema_api_secret)
    try:
        with connection:
            key = (yield from connection.get_public_key(requested_id))
            return(Key.encode(key))
    except GatewayError as exc:
        return(False)
Ejemplo n.º 2
0
def getpub(threema_id, threema_api_secret, requested_id):
    connection = Connection(threema_id, threema_api_secret)
    try:
        with connection:
            key = (yield from connection.get_public_key(requested_id))
            return (Key.encode(key))
    except GatewayError as exc:
        return (False)
Ejemplo n.º 3
0
async def capabilities(ctx, **arguments):
    # Create connection
    connection = Connection(arguments['from'], arguments['secret'], **ctx.obj)
    async with connection:
        # Lookup and format returned capabilities
        coroutine = connection.get_reception_capabilities(arguments['id'])
        capabilities_ = await coroutine
        click.echo(', '.join(
            sorted(capability.value for capability in capabilities_)))
Ejemplo n.º 4
0
async def send_file(ctx, **arguments):
    # Get key instances
    private_key = util.read_key_or_key_file(arguments['private_key'],
                                            Key.Type.private)
    if arguments['public_key'] is not None:
        public_key = util.read_key_or_key_file(arguments['public_key'],
                                               Key.Type.public)
    else:
        public_key = None

    # Create connection
    connection = Connection(identity=arguments['from'],
                            secret=arguments['secret'],
                            key=private_key,
                            **ctx.obj)

    async with connection:
        # Create message
        message = e2e.FileMessage(connection=connection,
                                  to_id=arguments['to'],
                                  key=public_key,
                                  file_path=arguments['file_path'],
                                  thumbnail_path=arguments['thumbnail_path'])

        # Send message
        click.echo(await message.send())
Ejemplo n.º 5
0
async def send_e2e(ctx, **arguments):
    # Get key instances
    private_key = util.read_key_or_key_file(arguments['private_key'],
                                            Key.Type.private)
    if arguments['public_key'] is not None:
        public_key = util.read_key_or_key_file(arguments['public_key'],
                                               Key.Type.public)
    else:
        public_key = None

    # Read message from stdin
    text = click.get_text_stream('stdin').read().strip()

    # Create connection
    connection = Connection(identity=arguments['from'],
                            secret=arguments['secret'],
                            key=private_key,
                            **ctx.obj)

    async with connection:
        # Create message
        message = e2e.TextMessage(connection=connection,
                                  to_id=arguments['to'],
                                  key=public_key,
                                  text=text)

        # Send message
        click.echo()
        click.echo(await message.send())
def main():
    connection = Connection('*YOUR_GATEWAY_THREEMA_ID', 'YOUR_GATEWAY_THREEMA_ID_SECRET')
    try:
        with connection:
            yield from send_via_id(connection)
            yield from send_via_email(connection)
            yield from send_via_phone(connection)
    except MessageError as exc:
        print('Error:', exc)
Ejemplo n.º 7
0
async def main():
    connection = Connection(
        identity='*YOUR_GATEWAY_THREEMA_ID',
        secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
    )
    try:
        async with connection:
            await send_via_id(connection)
            await send_via_email(connection)
            await send_via_phone(connection)
    except GatewayError as exc:
        print('Error:', exc)
def main():
    connection = Connection('*YOUR_GATEWAY_THREEMA_ID',
                            'YOUR_GATEWAY_THREEMA_ID_SECRET')
    try:
        with connection:
            print((yield from connection.get_credits()))
            print((yield from connection.get_id(phone='41791234567')))
            phone_hash = 'ad398f4d7ebe63c6550a486cc6e07f9baa09bd9d8b3d8cb9d9be106d35a7fdbc'
            print((yield from connection.get_id(phone_hash=phone_hash)))
            print((yield from connection.get_id(email='*****@*****.**')))
            email_hash = '1ea093239cc5f0e1b6ec81b866265b921f26dc4033025410063309f4d1a8ee2c'
            print((yield from connection.get_id(email_hash=email_hash)))
            key = (yield from connection.get_public_key('ECHOECHO'))
            print(Key.encode(key))
            print((yield from
                   connection.get_reception_capabilities('ECHOECHO')))
    except GatewayError as exc:
        print('Error:', exc)
Ejemplo n.º 9
0
async def create_application():
    # Create connection instance
    connection = Connection(identity='*YOUR_GATEWAY_THREEMA_ID',
                            secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
                            key='private:YOUR_PRIVATE_KEY')

    # Create the application and register the handler for incoming messages
    application = e2e.create_application(connection)
    e2e.add_callback_route(connection,
                           application,
                           handle_message,
                           path='/gateway_callback')
    return application
def main():
    connection = Connection(
        identity='*YOUR_GATEWAY_THREEMA_ID',
        secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
        blocking=True,
    )
    try:
        with connection:
            send_via_id(connection)
            send_via_email(connection)
            send_via_phone(connection)
    except GatewayError as exc:
        print('Error:', exc)
def main():
    connection = Connection('*YOUR_GATEWAY_THREEMA_ID', 'YOUR_GATEWAY_THREEMA_ID_SECRET')
    try:
        with connection:
            print((yield from connection.get_credits()))
            print((yield from connection.get_id(phone='41791234567')))
            phone_hash = 'ad398f4d7ebe63c6550a486cc6e07f9baa09bd9d8b3d8cb9d9be106d35a7fdbc'
            print((yield from connection.get_id(phone_hash=phone_hash)))
            print((yield from connection.get_id(email='*****@*****.**')))
            email_hash = '1ea093239cc5f0e1b6ec81b866265b921f26dc4033025410063309f4d1a8ee2c'
            print((yield from connection.get_id(email_hash=email_hash)))
            key = (yield from connection.get_public_key('ECHOECHO'))
            print(Key.encode(key))
            print((yield from connection.get_reception_capabilities('ECHOECHO')))
    except GatewayError as exc:
        print('Error:', exc)
Ejemplo n.º 12
0
def main():
    connection = Connection(id='*YOUR_GATEWAY_THREEMA_ID',
                            secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
                            key='private:YOUR_PRIVATE_KEY')
    try:
        with connection:
            yield from send(connection)
            yield from send_cached_key(connection)
            yield from send_cached_key_file(connection)
            yield from send_image(connection)
            yield from send_file(connection)
            yield from send_file_with_thumbnail(connection)
    except MessageError as exc:
        print('Error:', exc)
Ejemplo n.º 13
0
async def send_simple(ctx, **arguments):
    # Read message from stdin
    text = click.get_text_stream('stdin').read().strip()

    # Create connection
    connection = Connection(arguments['from'], arguments['secret'], **ctx.obj)
    async with connection:
        # Create message
        message = simple.TextMessage(connection=connection,
                                     to_id=arguments['to'],
                                     text=text)

        # Send message
        click.echo()
        click.echo(await message.send())
Ejemplo n.º 14
0
async def main():
    connection = Connection(
        identity='*YOUR_GATEWAY_THREEMA_ID',
        secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
        key='private:YOUR_PRIVATE_KEY',
    )
    try:
        async with connection:
            await send(connection)
            await send_cached_key(connection)
            await send_cached_key_file(connection)
            await send_image(connection)
            await send_video(connection)
            await send_file(connection)
            await send_file_with_thumbnail(connection)
    except GatewayError as exc:
        print('Error:', exc)
Ejemplo n.º 15
0
def serve():
    # Create connection instance
    connection = Connection(
        identity='*YOUR_GATEWAY_THREEMA_ID',
        secret='YOUR_GATEWAY_THREEMA_ID_SECRET',
        key='private:YOUR_PRIVATE_KEY'
    )

    # Create the application and register the handler for incoming messages
    application = create_application(connection)
    add_callback_route(connection, application, handle_message, path='/gateway_callback')

    # Create an SSL context to terminate TLS.
    # Note: It is usually advisable to use a reverse proxy instead in front of
    #       the server that terminates TLS, e.g. Nginx.
    ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
    ssl_context.load_cert_chain(certfile='YOUR_CERTFILE', keyfile='YOUR_KEYFILE')

    # Run a server that listens on any interface via port 8443. It will
    # gracefully shut down when Ctrl+C has been pressed.
    web.run_app(application, port=8443, ssl_context=ssl_context)
Ejemplo n.º 16
0
async def lookup(ctx, **arguments):
    modes = ['email', 'phone', 'id']
    mode = {
        key: value
        for key, value in arguments.items()
        if key in modes and value is not None
    }

    # Check that one of the modes has been selected
    if len(mode) != 1:
        error = 'Please specify exactly one ID, one email address or one phone number.'
        raise click.ClickException(error)

    # Create connection
    connection = Connection(arguments['from'],
                            secret=arguments['secret'],
                            **ctx.obj)
    async with connection:
        # Do lookup
        if 'id' in mode:
            public_key = await connection.get_public_key(arguments['id'])
            click.echo(Key.encode(public_key))
        else:
            click.echo(await connection.get_id(**mode))
Ejemplo n.º 17
0
async def credits(ctx, **arguments):
    # Create connection
    connection = Connection(arguments['from'], arguments['secret'], **ctx.obj)
    async with connection:
        # Get and print credits
        click.echo(await connection.get_credits())