PHP Webhook SmartApp Automation

Has anyone written a Webhook SmartApp Automation in PHP?

I’d like to see some code to jumpstart my development.

I got the example running and made some modifications to it in node.js (https://smartthings.developer.samsung.com/docs/examples/weather-light-example.html), but now I’d like to make a Drupal module using PHP.
Thanks!

I’m still working on this.
Currently having a challenge converting the node.js signature validation to php.
Has anyone done this?

Node.js
/**
* Verifies that the request is actually from SmartThings.
* @returns true if verified, false otherwise.
*/
function signatureIsVerified(req) {
// WARNING: DO NOT USE THIS IN PRODUCTION
// We will read the public key from FS everytime we need to verify
// COMMENT OUT THIS LINE INPRODUCTION
const publicKey = fs.readFileSync(’./config/smartthings_rsa.pub’, ‘utf8’);
// END WARNING
try {
let parsed = httpSignature.parseRequest(req);
if (!httpSignature.verifySignature(parsed, publicKey)) {
console.log(‘forbidden - failed verifySignature’);
return false;
}
} catch (error) {
console.error(error);
return false;
}
return true;
}

I have this working, and hope to post example code soon. If someone would find it useful, just let me know and I’ll share.

1 Like

So I continued my work, and built a Webhook for Drupal (which is PHP). If you don’t want to use the Drupal module and are not using Symphony, etc. but you still want to develop the webhook in PHP, then you could probably still download this drupal module code, and strip it down/ use it as a starting place.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.