Reading Answer from device

Pushsafer make it easy and safe to get push-notifications in real time on your Android or Windows mobile device, iPhone, iPad and Desktop!

Mit Pushsafer kann man in Echtzeit, einfach und sicher, Push-Benachrichtigungen auf sein iPhone, iPad, Android oder Windows Gerät sowie auf den Desktop senden lassen!

======================
Google Play
App Store
Windows Store
Homepage
phykc_pythonuser

Reading Answer from device

Postby phykc_pythonuser » 24. Jan 2022, 17:02

HI,

I got my python script working well to seen me temperature data every three hours. What I'd like to do is an an 'answer' to the notification e.g. a=1 supply some text, and then have my code read the 'answer' I supply. I can't figure out whether this is possible or not. I can see the answers in the online API log - but is there a way to 'read' these back to my code? Here is my code below:
import http.client, urllib
import base64
import time

class Message:
def __init__(self, k, m,t,i,s,v,p='',a='0',a0=""):
self.k=k
self.m=m
self.t=t
self.i=i
self.s=s
self.v=v
self.p=p
self.a=a
self.a0=a0
def send(self):
conn = http.client.HTTPSConnection("pushsafer.com:443")
conn.request("POST", "/api",
urllib.parse.urlencode({
"k": self.k, # Your Private Key
"m": self.m, # Message Text
"t": self.t, # Title of message
"i": self.i, # Icon number 1-98
"s": self.s, # Sound number 0-28
"v": self.v, # Vibration number 0-3
"p": self.p, # Picture Data URL with Base64-encoded string
"a":self.a, # For adding a response
"a0":self.a0, #For adding options
}), { "Content-type": "application/x-www-form-urlencoded" })
response = conn.getresponse()

print(response.status, response.reason)
data = response.read()
print(data)




def imageconvert(img):
encoded = base64.b64encode(open(img, "rb").read())
picture="data:image/png;base64,"+str(encoded)[2:]
return picture


#Add your own path and filename
picture=imageconvert('plot.png')
message='The message'
title='Alert title'

message=Message(k="<Your Private Key>",m=message,t=title, i='1',s='0',v='0',p=picture,a='1')
message.send()

User avatar
admin
Site Admin
Posts: 970
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: Reading Answer from device

Postby admin » 24. Jan 2022, 21:04

Hello,

use parameter a=1 to reply to a message!
parameter ao to have predefined option for an answer. Like ao=yes|no|maybe

To read answers, you have to use the "message read api" > https://www.pushsafer.com/en/pushapi#api-read

Kevin
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10

phykc_pythonuser

Re: Reading Answer from device

Postby phykc_pythonuser » 26. Jan 2022, 14:35

Excellent. Yes I worked out the a='1' part already, but reading back the 'answer' was baffling me. From your post and link, I figured it out. Briefly, I used a urllib.request using the address: "https://www.pushsafer.com/api-m?k="+ self.k+"&d="+self.deviceID and then I muddled my way to decode and then import into pandas dataframe, which I could then locate what I wanted. I need to become more familar with json, but using pandas I could locate the last alert sent, and the relevent data as a dict - then answer=message['answer'] There is probably an easier python solution, but it works.

User avatar
admin
Site Admin
Posts: 970
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: Reading Answer from device

Postby admin » 27. Jan 2022, 10:38

Great that you solution works! :D
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10


Who is online

Users browsing this forum: No registered users and 5 guests