Last active
February 5, 2021 23:08
-
-
Save erickvneri/2bd4e4a5a694dc130bd3d1f2f06d2117 to your computer and use it in GitHub Desktop.
"Hello world!" Notification SmartApp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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