This is a Google Messages Client library to send message with a backend .eg. with flask to send otp messages. This module uses your own number to work as a sms gateway api and you can send message to other person with your own number.
Project description
PYMESSAGES - Google Messages Client for Python
What is this?
- This is a Google Messages Client library to send message with a backend .eg. with flask to send otp messages. This module uses your own number to work as a sms gateway api and you can send message to other person with your own number. Ported from messages-web by Swapnil Soni.
How to use
- install the package from PyPI
pip install pymessages
- Use it
- Without credentials
from pymessages.client import MessagesClient
import json
import base64
import re
client = MessagesClient()
@client.on('qr-code')
async def on_qr_code(base64Image):
print("Generating qr code.")
with open("qr.jpg", "wb") as f:
f.write(base64.b64decode(re.sub(r'^data:image\/png;base64,','',base64Image)))
@client.on('authenticated')
async def on_authenticated(service):
print("Authenticated")
creds = await client.getCredentials()
with open("credentials.json", 'w') as f:
json.dump(creds, f, indent=4)
client.launch()
client.idle()
Then you can use credentials.json
file to login .
- With credentials
from pymessages.client import MessagesClient
import json
creds = MessagesClient.loadCredentialFile('credentials.json')
client = MessagesClient(creds)
@client.on('authenticated')
async def onAuthenticated(service):
inbox = await service.getInbox()
print(json.dumps(inbox, indent=4))
client.launch()
client.idle()
- send message
from pymessages.client import MessagesClient
creds = MessagesClient.loadCredentialFile('credentials.json')
client = MessagesClient(creds)
TO = "+919876543210"
MSG = "Test message sent using PyMessages wrapper."
@client.on('authenticated')
async def onAuthenticated(service):
print("Sending Messages.")
await service.sendMessage(TO, MSG)
print("Done.")
client.launch()
client.idle()
- Examples are given here.
Todos
- add pagination in getInbox
add sendMessage in Service- add public method in client to save credentials to a file
- sendMessage: parse to var to check if country code is included or not
- Rewrite docs with proper details
- detect if phone is not connected
- detect if web client is open in another browser or not
License
ISC - Swapnil Soni ©
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pymessages-0.1.4.tar.gz
(6.3 kB
view hashes)
Built Distribution
Close
Hashes for pymessages-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 481022a0bda4db7802ad27c124f80fad6ad9c6faec478096ae84395f2560f4de |
|
MD5 | 177ece779f427d3d9fab8a162d834ee9 |
|
BLAKE2b-256 | 164c60bfb90ee6df5388bc5c86fd2da5472450c324e8a6317e54967268220220 |