How to query the pushes for a device? - pushbullet

I want to use Pushbullet to send pushes from my phone to an application (which will then display it). This application is a service written in Python.
The basic reception of the realtime stream works:
import websocket
ws = websocket.create_connection("wss://stream.pushbullet.com/websocket/MYKEY")
while True:
result = ws.recv()
print"Received '%s'" % result
When pushing something to "All Devices", I get the expected output:
Received '{"type": "nop"}'
Received '{"type": "nop"}'
Received '{"type": "tickle", "subtype": "push"}'
Received '{"type": "nop"}'
Received '{"type": "tickle", "subtype": "push"}'
What I receive does not contain any data, the type is 'tickle', and the documentation says that
When you receive a tickle message, it means that a resource of the
type subtype has changed.
and to query the details on the server. The call which is mentioned there (GET https://api.pushbullet.com/v2/pushes?modified_after=1399008037.849) is not authenticated, so how to actually make the call?
Alternatively, I wanted to create a "device" for my application and send the pushes to it directly. But I cannot find any place in the docs where the process of impersonating a device would be described?

I gave a try to a GET with the Authorization header and it worked:
# ts is the timestamp one wants to check from on
ts = 0
headers = {'Authorization': 'Bearer MYKEY'}
r = requests.get(
'https://api.pushbullet.com/v2/pushes?modified_after={ts}'.format(ts=ts),
headers=headers
)
Since target_device_iden is sent with the push details when the push is directed to a specific device, my guess is that there is no "impersonation" (per the second part of my question): every device gets the whole feed and selects the events which were specifically directed to it (or mirrored ones)

Related

Redis PSUBSCRIBE Problems

A server is sending a message via Redis on a channel composed of some name and a unique id. I need to essentially find this channel and publish something back to it.
So far, I tried reading the documentation and experimenting with PSUBSCRIBE. However, the message that is received doesn't have the full channel name. It just has the pattern that I sent to PSUBSCRIBE. So, how can I go about finding the channel name?
I also included some code below if that would help understand my logic.
red = redis.StrictRedis(...)
pub = red.pubsub()
pub.psubscribe("name_pattern*")
for msg in pub.listen():
if msg["data"] == "...":
channel_name = msg["channel"]
red.publish(channel_name, "SOME MESSAGE")

How to forward a message in Telegram API

There are 2 methods in Telegram API that forward message:
messages.forwardMessage
messages.forwardMessages
I want to use forwardMessage method to forward a message from a channel, group or user to another one. Definition of this method is:
messages.forwardMessage#33963bf9 peer:InputPeer id:int random_id:long = Updates;
As you see this method has 3 input parameters:
peer that represents the channel, group or user that we forward message to. (Destination)
id that is message_id.
random_id that has internal use.
As we know the message_id is a unique number in a chat. so a message_id in a group has refers to a message that differs with the same message_id in other group.
So the main question is that how we determine the source peer of forwarding? Because the source peer is not determined by message_id.
P.S: My question is about methods in Telegram API, not Telegram Bot API.
There seems to an issue with ForwardMessageRequest which doesn't specify the source chat. Obviously message_id is not unique and through my tests I noticed wrong messages will be forwarded by just specifying the message_id. And I noticed message_id is not unique.
But the issue doesn't exist with ForwardMessagesRequest. Following is an example how to use the ForwardMessagesRequest version.
Forwarding Example:
Here is the code I used for testing (I am using Telethon for python, but it won't matter since it's directly calling telegram API):
source_chat = InputPeerChannel(source_chat_id, source_access_hash)
total_count, messages, senders = client.get_message_history(
source_chat, limit=10)
for msg in reversed(messages):
print ("msg:", msg.id, msg)
msg = messages[0]
print ("msg id:", msg.id)
dest_chat = InputPeerChat(dest_chat_id)
result = client.invoke(ForwardMessagesRequest(from_peer=source_chat, id=[msg.id], random_id=[generate_random_long()], to_peer=dest_chat))

What does MPNS response with status code 200 and notification status 'Dropped' mean?

For some push messages sent using MPNS I am getting a response with the following values:
statusCode = 200
notificationStatus = Dropped
deviceConnectionStatus = Connected
subscriptionStatus = Active
Looking at the only documentation I found it seems the meaning of this particular combination is not explained:
https://msdn.microsoft.com/library/windows/apps/ff941100(v=vs.105).aspx
What I want to know is if I should treat this as an error and if so, should I retry later or just give up?
Even if we cannot find a specific documentation to check the particular combination you provide, we can still analyze it based on our common experience:
200 OK means your request has been received successfully
Dropped means the MPNS has not received your request normally
Connected refers to your device status when the request is sent
The last header returns if the channel is still valid(Active) or not(Expired)
Thus, I think you can retry later since your channel is still valid.

Is it possible to send a single message to multiple numbers at a time using Twilio?

I'm developing an app that allows users to add people, info, and Name/phone, or select multiple numbers from their iPhone contact list to send SMS messages to the selected numbers. the problem is Twillio API needs to be call every time per number. Is their any way to call the API once for multiple numbers?
Is it possible to send message to multiple number at a time?
Is it possible to send multiple messages?
Thanks in advance
It's not possible, you need to iterate through the list and make one request per message (which is probably better than batching it and dealing with the potential of multiple errors / resends).
Each new SMS message from Twilio must be sent with a separate REST API request. To initiate messages to a list of recipients, you must make a request for each number to which you would like to send a message. The best way to do this is to build an array of the recipients and iterate through each phone number.
const numbersToMessage = ["+15558675310", "+14158141829", "+15017122661"]
numbersToMessage.forEach(async number => {
const message = await client.messages.create({
body: 'message body',
from: '+16468635472',
to: number
});
console.log(message.status)
});
Yes this is possible. Infact i'm trying to do the same thing at the moment(which is why i'm here) and Twilio has some advanced stuff that lets us achieve this.
Assuming you have a twilio ssid, twilio auth token and a twilio phone number, the next thing you have to do is create a "Twilio Messaging Service" from the dashboard. You can use the ssid of the created messaging service and use or if you want to send a message to like 10k numbers in one go, you create a "Twilio Notify Service" from the dashboard which takes the previously created messaging service as part of its configuration. Once this is done you can call the twilio.notifications.create() and pass bindings({ binding_type: 'sms', address: number }) for each phone number to it.
Complete explanation found in this twilio blog right here with perfectly working code.
https://www.twilio.com/blog/2017/12/send-bulk-sms-twilio-node-js.html
Yes it is possible to send message to multiple user's from your Twilio Number.
You can try this for your node.js file:
var arr = ["+1xxxxxxxxxx","+1xxxxxxxxx"];
arr.forEach(function(value){console.log(value);
client.messages.create({
to:value,
from: "+19253504188",
body: msg,
}, function(err,message){
console.log(err);
});
});
Yes it is possible. You have to provide the numbers as a list and iterate API call.
For example send a message to two numbers.
numbers = ['+1234562525','+1552645232']
for number in numbers:
proxy_client = TwilioHttpClient()
proxy_client.session.proxies = {'https': os.environ['https_proxy']}
client = Client(account_sid, auth_token, http_client=proxy_client)
message = client.messages \
.create(
body="Your message",
from_='Your Twilio number',
to=number
)

Passbook update tag: if-modified-since (null)

I am using Restlet2.0 (java) to build passbook server. When I send a Push Notification to APNs with PushToken, I got message 'if-modified-since (null)' from the server log:
entity.getText() : {"logs":["[2013-03-31 00:18:29 +1100] Get pass task
(pass type pass.xxxxxx.freehug, serial number ABC, if-modified-since
(null); with web service url
http://192.168.1.43:8080/passbook/restlet) encountered error:
Server response was malformed (Missing response data)"]}
This responding URL matches the router defined for the LoggingResource class (Line 4), but not the SerialNumbersPassWithDeviceResource class (Line 2) which defines the passUpdatedSince={tag} parameter to be captured for the latest pkpass comparison:
router.attach("/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}", DeviceRegistrationResource.class); //1/4. Registration - POST/DELETE
router.attach("/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}?passUpdatedSince={tag}", SerialNumbersPassWithDeviceResource.class); //2. SerialNumbers - GET
router.attach("/v1/passes/{passTypeIdentifier}/{serialNumber}", LatestVersionPassResource.class); //3. LatestVersion - GET
router.attach("/v1/log", LoggingResource.class); //5. Logging - POST
So where can I set the Update Tag (passUpdatedSince={tag}) and how can I get it under the router in above Line 2? Is my router setup for getting Update tag correct?
The passUpdatedSince={tag} value is set from the last successful response that your web service gave to the requsest:
https://{webServiceURL}/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}
You set it by providing a key of lastUpdated in the JSON dictionary response to the above request. The value can be anything you like, but the simplest approach would be to use a timestamp.
The if-modified-since value is set by the Last-Modified HTTP header sent with the last .pkpass bundle received matching the passTypeIdentifier and serialNumber. Again, you can choose what value to send in this header.
The specific error that you mention above is not due to either of these. It is caused by your web service not providing a .pkpass bundle in response to the request to:
https://{webServiceURL}/v1/passes/{passTypeIdentifier}/{serialNumber}
You may want to try hooking your device up to Xcode, turning on PassKit logging (Settings -> Developer), then monitoring the device's console log as you send the push. This may give you more detail as to why the device sent the message to your web service log.