Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"Hello world!" Notification SmartApp
'use strict';
const { SmartApp } = require('@smartthings/smartapp');
const notificationSmartApp = new SmartApp()
.appId('demo')
.disableCustomDisplayName(true)
.permissions(['r:locations:*'])
.page('mainPage', (ctx, page, configData) => {
page.section('Message:', section => {
section
.textSetting('notiMessage')
.description('')
.name('Type your message')
.required(true)
.minLength(4)
.maxLength(20)
.defaultValue('Hello world!')
})
})
.updated(async (ctx, updateData) => {
// Get message from SmartApp input
let message = ctx.config.notiMessage[0].stringConfig.value;
// Notification payload
let notiOpts = {
type: "ALERT",
locationId: ctx.locationId,
title: "Title",
message: message,
imageUrl: "https://tzeyang.com/wp-content/uploads/2018/03/Hello.jpg.png",
deepLink: {
type: "location",
id: "notification origin"
}
}
// Calling API after 1.5 seconds.
setTimeout(async () => {
let notiReq = await ctx.api.notifications.create(notiOpts);
console.log(notiReq);
}, 1500);
});
module.exports = notificationSmartApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment