-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (32 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const azure = require('azure-storage');
module.exports = async function (context, req) {
const textMessageBody = req.body;
const responseMessage = "";
const responseCode = 200;
if(textMessageBody.toLowerCase().includes("start") || textMessageBody.toLowerCase().includes("pause"))
{
context.log('Found a control message match in SMS, so will update Table Storage.');
var tableSvc = azure.createTableService(connectionString=process.env.AzureWebJobsStorage);
var newStatus = 'true';
if(textMessageBody.toLowerCase().includes("pause"))
newStatus = 'false';
var entGen = azure.TableUtilities.entityGenerator;
var serviceStatus = {
PartitionKey: entGen.String('consolechecker'),
RowKey: entGen.String('isenabled'),
state: entGen.Boolean(newStatus)
};
tableSvc.replaceEntity('jobcontrol', serviceStatus, function(error, result, response){
if(error) {
context.log("Failed to replace table entity!");
responseMessage = "Couldn't disable SMS send.";
responseCode = 500;
}
});
responseMessage = `SMS running: ${newStatus}`;
}
context.res = {
status: responseCode,
body: responseMessage
};
}