alexwhitman / node-pushbullet-api Goto Github PK
View Code? Open in Web Editor NEWPushBullet API module for Node.js
PushBullet API module for Node.js
I use pushbullet stream connection to listen for received messages in Node-Red "pushbullet in" node
When server disconnection occurs, this is not handled by client. Netstat shows
tcp 0 0 192.168.200.10:36578 104.154.164.197:443 ESTABLISHED 19338/node-red
but incoming messages are ignored.
As far as I know Node-Red has code to reconnect client after disconnection happens, but looks like it is not notified about disconnection currently.
Experimenting, I've changed the line
self.client = new WebSocketClient();
to
self.client = new WebSocketClient({keepalive: true, keepaliveInterval: 60000});
Now reconnection is handled correctly, but netstat shows ugly number of old connections after several reconnects:
tcp 0 0 192.168.200.10:48166 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87871 0 192.168.200.10:39832 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48183 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:48180 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87917 0 192.168.200.10:39826 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48189 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87801 0 192.168.200.10:58696 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48160 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48198 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48154 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:39834 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:48182 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48190 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:48181 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87917 0 192.168.200.10:39814 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48169 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:48165 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:39819 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 87917 0 192.168.200.10:39816 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87917 0 192.168.200.10:39824 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48188 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87801 0 192.168.200.10:58719 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48199 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:48205 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 87801 0 192.168.200.10:58707 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48163 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87917 0 192.168.200.10:39815 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48155 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:39817 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:48184 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 0 0 192.168.200.10:48164 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48161 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 87801 0 192.168.200.10:58706 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87917 0 192.168.200.10:39804 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48167 104.154.164.197:443 ESTABLISHED 2942/node-red
tcp 87871 0 192.168.200.10:39831 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87963 0 192.168.200.10:39806 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87917 0 192.168.200.10:39813 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 88680 0 192.168.200.10:49502 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 0 0 192.168.200.10:48162 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87825 0 192.168.200.10:39851 104.154.164.197:443 FIN_WAIT2 2942/node-red
tcp 87917 0 192.168.200.10:39825 104.154.164.197:443 FIN_WAIT2 2942/node-red
Could be there an option to always have only one active connection even after network reconnection happens?
Hello,
I'm using this lib' to push datas to specific persons for a while.
Now we are a lot more and I decided to give a try to push into a channel. I tried with postman without trouble but I can't find in the readme how to push in a damn channel.
Could anyone help me to find out ?
export default function sendNotification(query) {
const slugifiedQuery = slugify(query)
const channel_tag = 'myAwesomeTag'
return new Promise((resolveSending, rejectSending) => {
function send() {
return new Promise((resolve, reject) => {
const link = `http://aprettysite.com/${slugifiedQuery}.html`;
pusher.devices((error, devicesResponse) => {
const promises = [];
// For each device
_.each(devicesResponse.devices, (device) => {
// If active
if (device.active) {
// SendLink
const sendLink = new Promise((resolve, reject) => {
pusher.channelInfo(channel_tag,(error, response) => {
if(error) reject(null, null, "Can not find channel inforamtions");
console.log('\n CHANNEL INFO', response)
// Push a damn link with the reponse.
// I tried to replace response.iden by response.tag with no success
pusher.link(response.iden, 'Hello I want ' + query, link, function(error, response) {
console.log(error ? error: 'ok ' + response)
if (error) {
reject(null, null, "Can not send notification :(");
} else {
resolve(response);
}
});
});
});
promises.push(sendLink);
}
});
Promise.all(promises).then(resolve).catch(reject);
});
});
}
send()
.then(resolveSending)
.catch(rejectSending);
});
}
Here is my error
Error: The param 'device_iden' has an invalid value.
at PushBullet.handleError (pushbullet.js:126)
I know that pusher.link() is to push a link to someone, but I can't find for a channel.
pusher.link('u1qSJddxeKwOGuGW', 'GitHub', 'https://github.com/', function(error, response) {});
Thanks a lot :)
The push event is not being triggered because it is being sent as a tickle, not a message.
Some logging from my test script:
Pushbullet: message received: {"subtype":"push","type":"tickle"}
Pushbullet: tickle received: "push"
It seems to me that the code should become:
else if (data.type === 'tickle') {
if(data.subtype === 'push') {
self.emit('push');
} else {
self.emit('tickle', data.subtype);
}
}
The push-tickle contains no data, an API call is required to load the actual push AFAIK.
multiple calls of new Pushbullet... fail as the variable "request" is too overloaded...
simple patch is to change line 4 to be
var Request = require('request');
and then line 21 to be
request = Request.defaults({
Hi i try to use the module behind an http proxy.
I get this error :
2018-01-05 16:42:24 [10744] [error]: uncaughtException: connect ETIMEDOUT 216.58.208.211:443
Error: connect ETIMEDOUT 216.58.208.211:443
at Object._errnoException (util.js:999:13)
at _exceptionWithHostPort (util.js:1020:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1207:14) {
"error": {
"errno": "ETIMEDOUT",
"code": "ETIMEDOUT",
"syscall": "connect",
"address": "216.58.208.211",
"port": 443
},
"stack": "Error: connect ETIMEDOUT 216.58.208.211:443\n at Object._errnoException (util.js:999:13)\n at _exceptionWithHostPort (util.js:1020:20)\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1207:14)"
On the request
module page i can see that i can override defaults.
var r = request.defaults({'proxy':'http://localproxy.com'})
How can i use it with node-pushbullet-api
?
to be able to work with pushbullet in an typescript development process, @types/pushbullet
package needs to be available. Are you planning to dive into this in near future?
Pushbullet are deprecating the use of the id for the target device and have moved to using the iden field instead. Can this library be updated to accept either or both - as the iden is easier for users to see/check on the Pushbullet web site ?
Following your documentation. I am using version 3.0.0. What am I doing wrong? How can I get the useful information using your module?
import PushBullet from 'pushbullet'
import { API_KEY } from './config.js'
const pusher = new PushBullet(API_KEY)
const me = await pusher.me()
console.log('Me:', me)
Gives:
Me: Response {
size: 0,
[Symbol(Body internals)]: {
body: PassThrough {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
stream: PassThrough {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: true,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null
},
boundary: null,
disturbed: false,
error: null
},
[Symbol(Response internals)]: {
type: 'default',
url: 'https://api.pushbullet.com/v2/users/me',
status: 200,
statusText: '',
headers: {
'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
connection: 'close',
'content-length': '353',
'content-type': 'application/json; charset=utf-8',
date: 'Mon, 31 Jul 2023 21:08:44 GMT',
via: '1.1 google',
'x-ratelimit-limit': '16384',
'x-ratelimit-remaining': '16369',
'x-ratelimit-reset': '1690840927'
},
counter: 0,
highWaterMark: 16384
}
}
But when I use curl with the same access token I get:
curl --header 'Access-Token: <access_token>' "https://api.pushbullet.com/v2/users/me"
{"active":true,"iden":"....}
NPM audit output
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High │ Prototype Pollution in node-forge │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ node-forge │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >= 0.10.0 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-red-node-pushbullet │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ node-red-node-pushbullet > pushbullet > node-forge │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://npmjs.com/advisories/1561 │
└───────────────┴──────────────────────────────────────────────────────────────┘
Can you please provide a full working example of how to use the library in NodeJS?
I do not succeed in loading the library.
I always get errors such as
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by
the default ESM loader
or
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
This is my tsconfig.json
:
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES6",
"outDir": "./dist",
},
"exclude": [
"node_modules"
]
}
I tried to add and remove the type = "module"
line in package.json.
I tried
let PushBullet = require('pushbullet');
or
import {PushBullet} from 'pushbullet';
or
import {PushBullet} from '../node_modules/pushbullet/lib/pushbullet.js';
All without luck...
Please provide a working example with tsconfig.json and package.json included.
I am working on Windows 10, Node 14.0.3, npm 6.14.5.
Many thanks!
Hi, I have read your readme. Is there any possibility to push to a channel? I have seen that I can recieve the channel information, but I have not seen any possibility to push to a channel.
Thank you for your work!
when i push chinese like "sddf 好发挥科技交流 ddd", but get "sddf 好ddd" from the pushes
This simple test code hangs the process forever.
// pb.js
var PushBullet = require('pushbullet');
var pusher = new PushBullet(‘…’);
var stream = pusher.stream();
stream.on('connect', function() {
console.log('connected');
stream.close();
});
stream.on('close', function() {
console.log('closed');
});
stream.connect();
$ node pb.js
connected
<< process hangs here >>
Should probably call the callback with error
This repository doesn't contain some specific licensing. It would be nice to have a specific licence file.
Just for information:
We are scheduling a change to the Pusher system which may affect your integration.
CHANGE DESCRIPTION
In response to CVE-2014-3566 (https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3566) we will be removing support for SSLv3 from our REST API endpoints. After this change takes place, clients connection to the REST API will need to support TLS1.0 or above.
CHANGE WINDOW
The change will be applied between 2014-12-01 08:00 and 2014-12-01 16:00 UTC
ACTION REQUIRED
If you do not use SSL when connecting to the REST API then you need not take any action.
If you do connect over SSL, please ensure that you client supports at least TLS1.0.
In order to help test if your clients have the appropriate support or not, we have provisioned temporary REST API endpoints which match the SSL setup you will see in production after this change. If you wish to test your client, you may configure it to connect to:
If you are using a client library, please consult the documentation for how to alter the endpoint.
Notes on these endpoints:
If you have any concerns about the above, please get in touch with our support team.
Regards,
Pusher Change Management
PushBullet.link(deviceParams, name, url, callback)
The PushBullet API supports body
for all (i.e. link) pushes pushes, but the node-pushbullet-api does not, as far as the documentation tells me.
https://docs.pushbullet.com/#ratelimiting
pusher.note(email, title, note, function(err, res) {
console.log(res);
});
https://github.com/alexwhitman/node-pushbullet-api/blob/master/lib/pushbullet.js#L556
The argument entered into Error is .toString()ed.
err.message
is equal to [object Object]
Which tells you nothing.
Hi,
I am a new developer therefore many things are not so clear.
This could be really useful but I do nor really understand how to use the module.
Could you please add extra information in your Help?
For example how to start to use it in Meteor, how to import it.
Thanks!
require is not defined
module is not defined
Maybe I've missed something but it seems the global module isn't being found.
I'm trying to send a file using version 3.0.0 and it's uploading junk.
Do you get the same results?
import PushBullet from 'pushbullet'
import fs from 'fs'
import { API_KEY, DEVICE_NICKNAME } from './config.js'
console.log('Start')
let resp,obj
const pusher = new PushBullet(API_KEY)
resp = await pusher.devices()
obj = await resp.json()
let devices = obj.devices
let device = devices.find((d) => d.nickname === DEVICE_NICKNAME)
const destId = device.iden
console.log('Device Id:', destId)
resp = await pusher.file(destId, '1-jack.jpg', 'Pic of jack')
obj = await resp.json()
//console.log('File:',JSON.stringify(obj, null, 4))
let uploadedFile = obj.file_url
console.log('File url:' + uploadedFile)
resp = await fetch(uploadedFile)
//console.log('resp=', resp)
console.log('resp-len=', resp.headers.get('content-length'))
obj = await resp.text()
console.log('body=', obj)
Image file
root@docker:/dir# ls -l
-rwxrwxrwx 1 root root 1538023 Aug 1 00:11 1-jack.jpg
Results:
Start
Device Id: ujy8OAKQBl6sjCthOSFPQO
File url:https://dl3.pushbulletusercontent.com/abc.../1-jack.jpg
resp-len= 15
body= [object Object]
The file that has been uploaded just contains the string "[object Object]". I have checked this by downloading it in Firefox and curl. PushBullet app fails to show picture properly. Is there something obvious, I'm doing wrong? Do you get the same problem?
Hello!
The V2 API finally seems to be active.
https://docs.pushbullet.com/http/
The docs should probably be updated. Didn't have time to look over all of them at the moment but some things are in and some are out.
I have these two simple lines of code and it just fails to run :/
let PushBullet = require('pushbullet');
let pusher = new PushBullet('my-api-key');
Uncaught TypeError TypeError: PushBullet is not a constructor
at <anonymous> (-snip-\agent.js:6:16)
at Module._compile (internal/modules/cjs/loader:1159:14)
at Module._extensions..js (internal/modules/cjs/loader:1213:10)
at newLoader (d:\GitHub\muninn\node_modules\fix-esm\index.js:26:12)
at Module.load (internal/modules/cjs/loader:1037:32)
at Module._load (internal/modules/cjs/loader:878:12)
at Module.require (internal/modules/cjs/loader:1061:19)
at require (internal/modules/cjs/helpers:103:18)
at <anonymous> (-snip-\index.js:305:37)
at <anonymous> (-snip-\index.js:299:29)
at Module._compile (internal/modules/cjs/loader:1159:14)
at Module._extensions..js (internal/modules/cjs/loader:1213:10)
at Module.load (internal/modules/cjs/loader:1037:32)
at Module._load (internal/modules/cjs/loader:878:12)
at executeUserEntryPoint (internal/modules/run_main:81:12)
at <anonymous> (internal/main/run_main_module:23:47)
Per the 2015/9/11 change log entry (https://docs.pushbullet.com/#changelog), Contacts is no longer supported. Explains why I'm getting empty lists.
Hi!
Thank you for this awesome module.
Just to inform you that the channels are now in the API: https://docs.pushbullet.com/v2/subscriptions/
Regards
Based on the pushbullet API, the device iden is optional. If no device iden is present then the push is sent to all devices. Would it be possible to add that feature?
This package hasn't been updated in 3 years on npm, however, I see you making changes to the package. For example, the heartbeat functionality in the stream functionality is not on the npm package.
@alexwhitman Attempted to install and received this message:
npm WARN deprecated [email protected]: use uuid module instead
Hi. Thanks for setting up such a nice package.
I have PushBullet on two Android devices and also the Chrome extension. When using node-pushbullet-api
to push notifications, strange things happens sometimes.
If I use:
var PushBullet = require('pushbullet');
var pusher = new PushBullet('token');
pusher.devices((err, res) => {
res.devices.forEach(device => {
pusher.note(device.iden, 'Test', 'This is a test', function(error, response) {
})
})
})
It notifies the android devices, but in Chrome it opens the PushBullet webpage.
But if I use an example given in issue #15 :
var PushBullet = require('pushbullet');
var pusher = new PushBullet('token');
var deviceParams = {};
pusher.note(deviceParams, 'Test', 'This is a test', function(error, response) {
});
The strange behavior in Chrome does no happen and I got the Chome notification bubble.
Could you help me out?
If I read correctly this assumes the account you want ot be sending is your own account hence the API key, is there any chance you could add Oauth support so devs can use this with their users?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.