Maven
August 7, 2023, 11:21am
1
To send push notifications with my homey app am I implementing it correctly using the web api?
I currently get a “Missing Scopes” error when trying to send a push notification but I don’ believe i’m missing anything having “homey:manager:api” already.
sendPushNotification(users: User , message: string) {
const apiToken = await this.homey.api.getOwnerApiToken();
for (const user of users) {
this.log(user);
try {
const response = await this.homeyApi.flow.runFlowCardAction({
uri: 'homey:manager:mobile',
id: 'homey:manager:mobile:push_text',
headers: {
'Authorization': `Bearer ${apiToken}`
},
args: {
user: {
athomId: user.id,
id: user.id
},
text: message
},
});
......
Maybe this Homey script gets you going
On HomeyPro early 2023 version 10.0.0-rc.122, I found it necessary to give both “athomID” and “id” parameters for a successful push_text.
Example code:
// Tested using versions:
// - Homey Pro (Early 2023), version 10.0.0-rc.122
// - Homey Web App version 1.9.58
// Status as of 15-July-2023: working
// send message to specified user, or if none specified, then first user in getUsers list
var user_name = (typeof args[0] === 'string')
? args[0]
: '';
var user_athom_id = null;
var user_id …
Maven
August 7, 2023, 4:12pm
3
Thank you @Peter_Kawa . Though i have a working homeyscript, i will double check the post. I suspect though that my issue is more SDK related.
1 Like
The correct way of using the Web API in an app is by using homey-api
:
const { HomeyAPI } = require('homey-api');
...
const api = await HomeyAPI.createAppAPI({ homey: this.homey });
...
await api.flow.runFlowCardAction(...);
Although I’m not sure if this will solve your problem regarding missing scopes.
Documentation here: HomeyAPI - Homey Web API
1 Like
RonnyW
August 8, 2023, 5:21am
5
You can create a timeline notication from your app and the user can decide in timeline settings if he want to get an additional push message.
1 Like
Maven
August 8, 2023, 11:42am
6
Thank you for pointing this out @RonnyW , it’s easy to forget this option also exists. In my case however, this would kind of defeat the purpose of the app, so I’m still banging my head against the wall trying to solve the scopes issue.
Maven
August 8, 2023, 11:50am
7
@Jero could you maybe advice on my issue?
I’m on the new Homey Pro 2023. Am I missing something in the code or might this be related to the ongoing changes as outlined in https://community.homey.app/t/sending-notification-will-not-work-in-homeyscript/79235/5 .
Are you using homey-api
already with the code I outlined/linked to?
Jero
August 8, 2023, 1:05pm
9
An app is not allowed to start Flow card actions.
1 Like
Maven
August 8, 2023, 1:19pm
10
Yes, thanks. this all works as per the api guides.
Maven
August 8, 2023, 2:38pm
11
So no way to send push notifications to homey mobile trough a homey app?
Jero
August 8, 2023, 5:04pm
12
No, not sure how you already are so far in development without being able to test those cards. Although I like the app idea.
Maven
August 8, 2023, 6:16pm
13
Damn! thank you for your support though.
I was just practising based on your videos. Its a fully working app except the scope bounce when sending the notification - thought I just missed something .
This works wonders for me in HomeyScript so wanted to make it readily available. Guess ill trash it for now.