Coder Social home page Coder Social logo

python-thr's Introduction

Thr

A small Threema Gateway library that focuses on easy usage.

Python package

Functionality

  • Send text messages
  • Send files
  • Lookup contacts
  • Receive messages

Usage

First, initialize the API without own API secrets.

threema = thr.Threema(
    identity="*MYIDENT", 
    key='717b1fb0f3e6888454f21a012cec6be6181a308ce89f4a733869848fd6ed74bb', 
    secret='w2kdj25yh1Ep81oP')

Lookup Contacts

In order to send end-to-end encrypted messages, you need the public key of the recipient. If you don't have it you can look-up the public key using the threema ID:

contact = threema.lookup("FMD1R5RX")

Send a Text Message

There is a shorthand function to send text messages:

threema.send_text_message(recipient=contact, content="Hello!")

The more verbose way would be to first, create a TextMessage and afterwards send it:

message = TextMessage("Hello!")
threema.send_message(recipient=contact, message=message)

Send a File

If you want to send a file with a thumbnail attached, you have to upload the thumbnail as well. The key must be the same, as the one for the file.

# Upload the file
message = threema.upload_file(filename="image.jpg")

# Optionally upload a thumbnail
with open("thumbnail.jpg", "rb") as thumnail_file:
    thumbnail_content = thumnail_file.read()
message.thumbnail_blob_id = threema.upload_thumbnail(thumbnail_content, key=message.key)

# Send the message
threema.send_message(
    message=message, 
    recipient=contact)

python-thr's People

Contributors

coffeemakr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.