buildfire: Is it possible to access clock and alarms functions through buildfire sdk - buildfire

Is it possible to access the devices clock and alarm functions? I haven't seen a buildfire plugin for this in the marketplace.

Yes, you can use the BuildFire local notifications API schedule function to schedule an event.
Here's sample code:
var options = {
title: 'Wake Up',
text: 'Time to get moving',
data: '',
at: sendTime
};
buildfire.notifications.localNotification.schedule(options, function (err, data) {
});

Related

How to set up a google calendar web hook in Nodejs?

I looked at the google calendar node js api and this wasn’t clear.
How do I set up a web hook using the Nodejs google calendar library?
I want to tell google to ping a server when my clients has either added or changed an appointment on his google calendar?
How can I use Nodejs to set up the watch?
The Google Calendar API provides push notifications that let you watch for changes to resources (Webhooks).
Google Calendar Push notification                                                                                
View in Fusebit
const calendar = googleClient.calendar('v3');
const watchResponse = await calendar.events.watch({
resource: {
id: uuidv4(),
type: 'web_hook',
address: 'Your webhook address here'
},
calendarId: 'primary'
});
const { data } = watchResponse;
console.log('Calendar Webhook created', data);

notifier.on click event is not fired in Windows Action Center

I am using the node-notifier package for notification but I have one problem. notifier.on click event is not fired in Windows Action Center
notifier.notify(
{
appId: "com.electron.demo", // Absolute path (doesn't work on balloons),
title: "Alert Message",
message: "Click to view",
icon: path.join(__dirname, 'msicon.png'),
wait: true,
timeout: false,
id: "demo app"
},
function(err, response) {
// Response is response from notification
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
notifier.on("click", function(notifierObject, options, event) {
// Triggers if `wait: true` and user clicks notification
var request = new sql.Request();
let username = userName;
request.query("update alerts.dbo.groupmessages set isRead = 1\
where pk = '"+ recordset.recordset[i].pk + "'\
and userFK = (select pk from alerts.dbo.users where username = '"+ username + "')\
and groupFK = (select groupFK from alerts.dbo.users where username = '"+ username + "')", function (err, recordset) {
if (err) throw err
console.log(err, recordset, 'User shit');
});
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 400,
height: 400,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
// and load the index.html of the app.
ejse.data('message', recordset.recordset[i].message);
win.loadFile('index.ejs')
}
createWindow();
});
});
});
notifier.on click event is not fired in only Windows Action Center. please let me know the reason and solution as well. Thanks.
Action Center requires separate implementation in native code, which node-notifier doesn't have.
You can try node-powertoast instead and use the onActivated callback:
npm i node-powertoast
const toast = require('powertoast');
toast({
title: "Hello",
message: "world",
callback: {
timeout: 5000, //keep-a-live in ms
onActivated: ()=>{ console.log("activated") },
onDismissed: (reason)=>{ console.log(reason) }
})
.then(()=> console.log("Notified")
.catch(err => console.error(err));
As for the reason:
You can see for other projects it's a significant undertaking and the following project, for example, seems to have Action Center support stuck in limbo for 2 years now: https://github.com/mohabouje/WinToast/issues/35 People trying to implement it themselves appear to have gotten stuck, and have had difficulty getting it implemented correctly.
It's just hard to do.
Notification doesn't get clicks because not all Action Center requirements are fulfilled.
In general Windows notifications have three types of activation: foreground, background and protocol.
In any case you will need to have the following:
Have a shortcut in Start Menu with AppUserModelId property. Please consult your installer on how to do it or use shell.readShortcutLink and shell.writeShortcutLink Electron API. Specifically WiX allows you to specify appUserModelId and toastActivatorClsid in options.
Specify AppUserModelId in the app.
app.setAppUserModelId('AppUserModelId');
Register a custom protocol and some reaction to it. For example like this:
app.setAsDefaultProtocolClient('example');
To use foreground or background you need to:
Have a shortcut in Start Menu with ToastActivatorCLSID property. See above on how to do it.
Use a project like electron-windows-interactive-notifications to register a COM server with the specified earlier ToastActivatorCLSID and a custom protocol of your choice and call:
registerComServer();
registerActivator();
I won't get deep into details on how to react to custom protocol but you will need to parse command line args in search for example: and also expect it in the second-instance hook if the app is already launched.
To use protocol type no extra actions needed.
After that even standard Electron notifications will get clicks from Action Center.
But how to use these protocols and get feature rich notifications?
Electron allows you to specify toastXml directly!
Let's say here's your notification. It will open https://google.com even if clicked from Action Center.
const notification = new Notification({
toastXml: `
<toast launch="https://google.com" activationType="protocol">
<visual>
<binding template="ToastGeneric">
<text>Wonderman meets Superwoman</text>
<text>In the eve of the new millennium, Wonderman challenges Superwoman to a bliniking contest.</text>
<text placement="attribution">Mars Press</text>
</binding>
</visual>
</toast>
`,
});
notification.show();
This notification simply opens Google. You can get more ideas at Notification Visualizer App

Google Cloud HTTP function by webhook: Request body is missing data

Im integrating the Zoom API with my Firebase app, and to do so I'm relying on Zooms pre-made webhooks to run an HTTP function on my Firebase for various events like "meeting started" and "meeting ended". Zoom API reference: https://marketplace.zoom.us/docs/guides/webhooks
This is the Google Cloud function that the Zoom API is calling:
exports.zoomTestA = functions.https.onCall((req, res) => {
console.log(req);
let data = req.body;
var xmlData = data.toString();
console.log(xmlData);
});
Here is the payload sent by Zoom:
{
"event": "meeting.ended",
"payload": {
"account_id": "LTf-KjgUTR2df-knT8BVEw",
"object": {
"duration": 0,
"start_time": "2019-05-07T14:02:51Z",
"timezone": "",
"topic": "Alexander Zoom Meeting",
"id": "864370042",
"type": 1,
"uuid": "2h/SWVrrQMu7fcbpLUly3g==",
"host_id": "Ty6ykNolSU2k1N4oc0NRcQ"
}
}
This causes this error to appear in my Google Cloud console:
Request body is missing data. { event: 'meeting.ended',
payload:
{ account_id: 'LTf-KjgUTR2df-knT8BVEw',
object:
{ duration: 0,
start_time: '2019-04-30T14:23:44Z',
timezone: '',
topic: 'Alexander\'s Zoom Meeting',
id: '837578313',
type: 1,
uuid: 'WotbHO3RRpSviETStKEGYA==',
host_id: 'Ty6ykNolSU2k1N4oc0NRcQ' } } }
The request body that Zoom sends is not wrapped in in a "data: {}" tag as required by Google Cloud functions. I've found solutions to this problem if you can control the payload here: Dart json.encode is not encoding as needed by Firebase Function .
My problem is that I am unable to alter the request that the Zoom API sends. Is there any way I can still accept the request in my Google Cloud function? Or is there any way to alter the format of the request sent by Zoom? I'm unable to find references for either.
One potential solution would be to set up another server that receives the request by Zoom, format it to Google Cloud functions specifications, and then pass it on to my Google Cloud function. I would however like to avoid stepping out of the Google Cloud eco-system.
Is this problem solvable on the Google Cloud platform?
So I figured it out. In Firebase / Google Cloud functions you can either make HTTP-functions with
functions.https.onCall((req, res) => {
var data = req.body;
and
functions.https.onRequest((req, res) => {
var data = req.body;
The difference seems to be that onCall is made for being used within the Firebase/ Google Cloud functions environment. However if you wan external functions you need to use onRequest as this does not require specific formatting of the payload.
Using onRequest instead solved all my problems.

Twilio Function to send VoiceMail or Recording to Email

Twilio Stuido does not provide a native way to email a recording therefore this needs to be coded. In this example, a voicemail has been taken of a users call. Now that we have the recording a Twilio Function is created (NodeJS) to send this recording to email.
In the sample code below the function is failing however there is no available debug tool inside the Twilio Console for dealing with functions. NodeJS is fairly new to us so this maybe easy for someone to spot.
Possible other errors may be however:
Incorrect gmail authentication (although the details are correct in terms of username and password, perhaps this is not how you configure google apps to send the email)
Inability to import or incorrectly importation of the nodemailer dependency into Twilio
Bad NodeJS skills
The input variables are:
attachment
{{widgets.Voicemail_Recording.RecordingUrl}}
- which contains the URL to the voicemail recording.
lang
- the language of the caller (based on IVR choices earlier).
phone_number
{{trigger.call.From}}
NodeJS Twilio Function
var mailer = require('nodemailer');
mailer.SMTP = {
host: 'smtp.gmail.com',
port:587,
use_authentication: true,
user: 'info#example.com',
pass: '*********'
};
exports.handler = function(context, event, callback) {
mailer.send_mail({
sender: event.phone_number + '<info#example.com>',
to: 'info#example.com',
subject: 'Voicemail (' + event.lang + ')',
body: 'mail content...',
attachments: [{'filename': event.attachment, 'content': data}]
}), function(err, success) {
if (err) {
}
}
};
Sam here from Twilio's support team - I just released a blog post that should help with this. It shows how to forward voicemails with Studio, Functions, and SendGrid. Check it out here: https://www.twilio.com/blog/forward-voicemail-recordings-to-email

Using Twilio API resources within Twilio Functions

I've nearly finished my phone system with twilio and the final part is a voicemail playback. If the call fails or is declined, the calling party can leave a message and it saves to the twilio recordings. All server side code is done in Twilio Functions.
Now I want the end party to be able to check their voicemail by dialing an extension and playing back the saved messages. Everything up to the playing back of messages is done because I can't get the recording uri from a list of recordings.
Note NodeJS is not my strong suite.
I have tried playing back all recordings with:
exports.handler = function(context, event, callback) {
const twilioClient = context.getTwilioClient();
let response = new Twilio.twiml.VoiceResponse();
twilioClient.recordings.each(recording => response.play(recording.uri));
callback(null, response);
}
But I don't the expected result (i.e. I get a 200 OK and the <Response/> xml). I have Enable ACCOUNT_SID and AUTH_TOKEN enabled in the functions configuration.
I feel like it has something to do with the callback and the request to the api being asynchronous but I couldn't find much information on the recordings docs (https://www.twilio.com/docs/api/voice/recording).
Found the documentation I was after in the automated docs (https://www.twilio.com/docs/libraries/reference/twilio-node/3.11.2/Twilio.Api.V2010.AccountContext.RecordingList.html).
client.recordings.each({
callback: function (recording) {
response.say('New Message');
const recordingSid = recording.sid;
},
done: function () {
callback(null, response);
},
});

Resources