Skip to content

Instantly share code, notes, and snippets.

@erickvneri
Last active February 5, 2021 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erickvneri/2bd4e4a5a694dc130bd3d1f2f06d2117 to your computer and use it in GitHub Desktop.
Save erickvneri/2bd4e4a5a694dc130bd3d1f2f06d2117 to your computer and use it in GitHub Desktop.
"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