Best JavaScript code snippet using redwood
MMM-Voice-Commands.js
Source:MMM-Voice-Commands.js
...8 commands: {9 "socket test :payload": "TEST_SOCKET",10 "function test :payload": function(payload) {11 alert("Test: " + payload);12 } //in these functions 'this' is bound to the module so this.sendNotification() is valid13 }14 },15 start: function() {16 this.rawCommands = this.config.commands;17 this.autoStart = this.config.autoStart;18 this.activateCommand = this.config.activateCommand;19 this.deactivateCommand = this.config.deactivateCommand;20 this.alertHeard = this.config.alertHeard;21 this.debug = this.config.debug;22 this.commands = {};23 this.active = false;24 this.initAnnyang();25 },26 notificationReceived: function(notification, payload) {27 if (notification === "DOM_OBJECTS_CREATED") {28 this.sendSocketNotification("START", {29 config: this.config,30 modules: this.modules31 });32 } else if (notification === "REGISTER_VOICE_MODULE") {33 if (34 Object.prototype.hasOwnProperty.call(payload, "mode") &&35 Object.prototype.hasOwnProperty.call(payload, "sentences")36 ) {37 this.modules.push(payload);38 }39 }40 initAnnyang: function() {41 const self = this;42 if (annyang) {43 //Iterate over commands list to create a valid annyang command object44 for (var key in self.rawCommands) {45 if (self.rawCommands.hasOwnProperty(key)) {46 //If the property is already a function, leave it that way. Otherwise assume it is a socket name47 if (typeof self.rawCommands[key] !== "function") {48 //Construct a valid function...49 function createCommand(socket) {50 return function(payload) {51 self.sendNotification(socket, payload);52 };53 }54 //...And then put it in the object55 self.commands[key] = createCommand(self.rawCommands[key]);56 } else {57 self.commands[key] = self.rawCommands[key].bind(self);58 }59 }60 }61 if (self.autoStart) {62 annyang.addCommands(self.commands);63 self.active = true;64 }65 const standardCommands = {};66 standardCommands[self.activateCommand] = function() {67 if (!self.active) {68 self.addCommands(self.commands);69 self.active = true;70 self.sendNotification("SHOW_ALERT", {71 type: "notification",72 title: "Voice Commands",73 message: "Activated"74 });75 } else {76 self.sendNotification("SHOW_ALERT", {77 type: "notification",78 title: "Voice Commands",79 message: "Already Active"80 });81 }82 };83 standardCommands[self.deactivateCommand] = function() {84 if (self.active) {85 self.removeCommands(self.commands);86 self.active = false;87 self.sendNotification("SHOW_ALERT", {88 type: "notification",89 title: "Voice Commands",90 message: "Deactivated"91 });92 } else {93 self.sendNotification("SHOW_ALERT", {94 type: "notification",95 title: "Voice Commands",96 message: "Already Deactivated"97 });98 }99 };100 annyang.addCommands(standardCommands);101 annyang.start();102 if (self.debug) {103 annyang.addCallback("result", function(e) {104 Log.log(e);105 });106 annyang.addCallback("error", function(e) {107 Log.log(e);108 });109 }110 // This is the code that I added to add a similar experience to Hello-Lucy111 if (self.alertHeard) {112 annyang.addCallback("result", function(e) {113 for (var i = 0; i < e.length; i++) {114 // Get First result from annyang, which will be closest speech match115 // Format notification into format to match MMM-HelloLucy116 var notification = e[i]117 .toUpperCase()118 .trim()119 .replace(" ", "_");120 // MMM-Voice-Commands sends notification to MMM-GoogleMapsTraffic to HIDE121 if (notification === "HIDE_TRAFFIC") {122 self.sendNotification("HIDE_TRAFFIC");123 }124 // Check if notification is requesting location125 else if (notification.indexOf("SHOW_TRAFFIC") > -1) {126 // MMM-Voice-Commands sends notification to MMM-GoogleMapsTraffic to SHOW Default location per config127 if (notification === "SHOW_TRAFFIC") {128 self.sendNotification("SHOW_TRAFFIC");129 }130 // MMM-Voice-Commands sends notification to MMM-GoogleMapsTraffic to SHOW passed location from voice131 else {132 var indexOfNotification = notification.indexOf("SHOW_TRAFFIC");133 var strippedPayload = notification134 .replace("_", " ")135 .substr(ind + 8, notification.length)136 .trim();137 var location = st138 .replace("of", "")139 .trim()140 .replace("for", "")141 .trim();142 self.sendNotification("SHOW_TRAFFIC", location);143 }144 }145 ////////////////////////////////////////////////////////////////////////////////////////////////////////146 // Add Additional Modules similar to below147 // MMM-Voice-Commands sends notification to MMM-Cocktails to HIDE148 else if (notification === "HIDE_COCKTAILS") {149 self.sendNotification("HIDE_COCKTAILS");150 }151 // MMM-Voice-Commands sends notification to MMM-Cocktails to SHOW152 else if (notification === "SHOW_COCKTAILS") {153 self.sendNotification("SHOW_COCKTAILS");154 }155 // MMM-Voice-Commands sends notification to MMM-Clock to HIDE156 else if (notification === "HIDE_CLOCK") {157 self.sendNotification("HIDE_CLOCK");158 }159 // MMM-Voice-Commands sends notification to MMM-Clock to SHOW160 else if (notification === "SHOW_CLOCK") {161 self.sendNotification("SHOW_CLOCK");162 }163 // MMM-Voice-Commands sends notification to MMM-Newsfeed to HIDE164 else if (notification === "HIDE_NEWSFEED") {165 self.sendNotification("HIDE_NEWSFEED");166 }167 // MMM-Voice-Commands sends notification to MMM-Newsfeed to SHOW168 else if (notification === "SHOW_NEWSFEED") {169 self.sendNotification("SHOW_NEWSFEED");170 }171 // MMM-Voice-Commands sends notification to MMM-AlarmClock to HIDE172 else if (notification === "HIDE_ALARM") {173 this.sendNotification("HIDE_ALARM");174 }175 // MMM-Voice-Commands sends notification to MMM-AlarmClock to SHOW176 else if (notification === "SHOW_ALARM") {177 this.sendNotification("SHOW_ALARM");178 }179 // MMM-Voice-Commands sends notification to MMM-Back to HIDE180 else if (notification === "HIDE_BACKGROUND") {181 this.sendNotification("HIDE_BACKGROUND");182 }183 // MMM-Voice-Commands sends notification to MMM-Back to SHOW184 else if (notification === "SHOW_BACKGROUND") {185 this.sendNotification("SHOW_BACKGROUND");186 }187 // MMM-Voice-Commands sends notification to calendar to HIDE188 else if (notification === "HIDE_CALENDAR") {189 this.sendNotification("HIDE_CALENDAR");190 }191 // MMM-Voice-Commands sends notification to calendar to SHOW192 else if (notification === "SHOW_CALENDAR") {193 this.sendNotification("SHOW_CALENDAR");194 }195 // MMM-Voice-Commands sends notification to MMM-CARDS to HIDE196 else if (notification === "HIDE_CARDS") {197 this.sendNotification("HIDE_CARDS");198 }199 // MMM-Voice-Commands sends notification to MMM-CARDS to SHOW200 else if (notification === "SHOW_CARDS") {201 this.sendNotification("SHOW_CARDS");202 }203 // MMM-Voice-Commands sends notification to MMM-Census to HIDE204 else if (notification === "HIDE_CENSUS") {205 this.sendNotification("HIDE_CENSUS");206 }207 // MMM-Voice-Commands sends notification to MMM-Census to SHOW208 else if (notification === "SHOW_CENSUS") {209 this.sendNotification("SHOW_CENSUS");210 }211 // MMM-Voice-Commands sends notification to MMM-CLOCK to HIDE212 else if (notification === "HIDE_CLOCK") {213 this.sendNotification("HIDE_CLOCK");214 }215 // MMM-Voice-Commands sends notification to MMM-CLOCK to SHOW216 else if (notification === "SHOW_CLOCK") {217 this.sendNotification("SHOW_CLOCK");218 }219 // MMM-Voice-Commands sends notification to MMM-COCKTAILS to HIDE220 else if (notification === "HIDE_COCKTAILS") {221 this.sendNotification("HIDE_COCKTAILS");222 }223 // MMM-Voice-Commands sends notification to MMM-COCKTAILS to SHOW224 else if (notification === "SHOW_COCKTAILS") {225 this.sendNotification("SHOW_COCKTAILS");226 }227 // MMM-Voice-Commands sends notification to compliments to HIDE228 else if (notification === "HIDE_COMPLIMENTS") {229 this.sendNotification("HIDE_COMPLIMENTS");230 }231 // MMM-Voice-Commands sends notification to compliments to SHOW232 else if (notification === "SHOW_COMPLIMENTS") {233 this.sendNotification("SHOW_COMPLIMENTS");234 }235 // MMM-Voice-Commands sends notification to MMM-NOAA to HIDE236 else if (notification === "HIDE_COWBOY") {237 this.sendNotification("HIDE_COWBOY");238 }239 // MMM-Voice-Commands sends notification to MMM-NOAA to SHOW240 else if (notification === "SHOW_COWBOY") {241 this.sendNotification("SHOW_COWBOY");242 }243 // MMM-Voice-Commands sends notification to MMM-EOL to HIDE244 else if (notification === "HIDE_DARWIN") {245 this.sendNotification("HIDE_DARWIN");246 }247 // MMM-Voice-Commands sends notification to MMM-EOL to SHOW248 else if (notification === "SHOW_DARWIN") {249 this.sendNotification("SHOW_DARWIN");250 }251 // MMM-Voice-Commands sends notification to MMM-EARTH to HIDE252 else if (notification === "HIDE_EARTH") {253 this.sendNotification("HIDE_EARTH");254 }255 // MMM-Voice-Commands sends notification to MMM-EARTH to SHOW256 else if (notification === "SHOW_EARTH") {257 this.sendNotification("SHOW_EARTH");258 }259 // MMM-Voice-Commands sends notification to MMM-EyeCandy to HIDE260 else if (notification === "HIDE_EYECANDY") {261 this.sendNotification("HIDE_EYECANDY");262 }263 // MMM-Voice-Commands sends notification to MMM-EyeCandy to SHOW264 else if (notification === "SHOW_EYECANDY") {265 this.sendNotification("SHOW_EYECANDY");266 }267 // MMM-Voice-Commands sends notification to MMM-Events to HIDE268 else if (notification === "HIDE_EVENTS") {269 this.sendNotification("HIDE_EVENTS");270 }271 // MMM-Voice-Commands sends notification to MMM-Events to SHOW272 else if (notification === "SHOW_EVENTS") {273 this.sendNotification("SHOW_EVENTS");274 }275 // MMM-Voice-Commands sends notification to MMM-rfacts to HIDE276 else if (notification === "HIDE_FAX") {277 this.sendNotification("HIDE_FAX");278 }279 // MMM-Voice-Commands sends notification to MMM-rfacts to SHOW280 else if (notification === "SHOW_FAX") {281 this.sendNotification("SHOW_FAX");282 }283 // MMM-Voice-Commands sends notification to MMM-Glock to HIDE284 else if (notification === "HIDE_FLIPPER") {285 this.sendNotification("HIDE_FLIPPER");286 }287 // MMM-Voice-Commands sends notification to MMM-Glock to SHOW288 else if (notification === "SHOW_FLIPPER") {289 this.sendNotification("SHOW_FLIPPER");290 }291 // MMM-Voice-Commands sends notification to MMM-FlightsAbove to HIDE292 else if (notification === "HIDE_FLIGHTS") {293 this.sendNotification("HIDE_FLIGHTS");294 }295 // MMM-Voice-Commands sends notification to MMM-FlightsAbove to SHOW296 else if (notification === "SHOW_FLIGHTS") {297 this.sendNotification("SHOW_FLIGHTS");298 }299 // MMM-Voice-Commands sends notification to MMM-Fortune to HIDE300 else if (notification === "HIDE_FORTUNE") {301 this.sendNotification("HIDE_FORTUNE");302 }303 // MMM-Voice-Commands sends notification to MMM-Fortune to SHOW304 else if (notification === "SHOW_FORTUNE") {305 this.sendNotification("SHOW_FORTUNE");306 }307 // MMM-Voice-Commands sends notification to MMM-Gas to HIDE308 else if (notification === "HIDE_GAS") {309 this.sendNotification("HIDE_GAS");310 }311 // MMM-Voice-Commands sends notification to MMM-Gas to SHOW312 else if (notification === "SHOW_GAS") {313 this.sendNotification("SHOW_GAS");314 }315 // MMM-Voice-Commands sends notification to MMM-JEOPARDY to HIDE316 else if (notification === "HIDE_JEOPARDY") {317 this.sendNotification("HIDE_JEOPARDY");318 }319 // MMM-Voice-Commands sends notification to MMM-JEOPARDY to SHOW320 else if (notification === "SHOW_JEOPARDY") {321 this.sendNotification("SHOW_JEOPARDY");322 }323 // MMM-Voice-Commands sends notification to MMM-LICE to HIDE324 else if (notification === "HIDE_LICE") {325 this.sendNotification("HIDE_LICE");326 }327 // MMM-Voice-Commands sends notification to MMM-LICE to SHOW328 else if (notification === "SHOW_LICE") {329 this.sendNotification("SHOW_LICE");330 }331 // MMM-Voice-Commands sends notification to MMM-URHere to HIDE332 else if (notification === "HIDE_LOCATION") {333 this.sendNotification("HIDE_LOCATION");334 }335 // MMM-Voice-Commands sends notification to MMM-URHere to SHOW336 else if (notification === "SHOW_LOCATION") {337 this.sendNotification("SHOW_LOCATION");338 }339 // MMM-Voice-Commands sends notification to MMM-Lottery to HIDE340 else if (notification === "HIDE_LOTTERY") {341 this.sendNotification("HIDE_LOTTERY");342 }343 // MMM-Voice-Commands sends notification to MMM-Lottery to SHOW344 else if (notification === "SHOW_LOTTERY") {345 this.sendNotification("SHOW_LOTTERY");346 }347 // MMM-Voice-Commands sends notification to MMM-EasyPix to HIDE348 else if (notification === "HIDE_LUCY") {349 this.sendNotification("HIDE_LUCY");350 }351 // MMM-Voice-Commands sends notification to MMM-EasyPix to SHOW352 else if (notification === "SHOW_LUCY") {353 this.sendNotification("SHOW_LUCY");354 }355 // MMM-Voice-Commands sends notification to MMM-Lunartic to HIDE356 else if (notification === "HIDE_MOON") {357 this.sendNotification("HIDE_MOON");358 }359 // MMM-Voice-Commands sends notification to MMM-Lunartic to SHOW360 else if (notification === "SHOW_MOON") {361 this.sendNotification("SHOW_MOON");362 }363 // MMM-Voice-Commands sends notification to MMM-NASA to HIDE364 else if (notification === "HIDE_NASA") {365 this.sendNotification("HIDE_NASA");366 }367 // MMM-Voice-Commands sends notification to MMM-NASA to SHOW368 else if (notification === "SHOW_NASA") {369 this.sendNotification("SHOW_NASA");370 }371 // MMM-Voice-Commands sends notification to MMM-NEO to HIDE372 else if (notification === "HIDE_NEO") {373 this.sendNotification("HIDE_NEO");374 }375 // MMM-Voice-Commands sends notification to MMM-NEO to SHOW376 else if (notification === "SHOW_NEO") {377 this.sendNotification("SHOW_NEO");378 }379 // MMM-Voice-Commands sends notification to newsfeed to HIDE380 else if (notification === "HIDE_NEWS") {381 this.sendNotification("HIDE_NEWS");382 }383 // MMM-Voice-Commands sends notification to newsfeed to SHOW384 else if (notification === "SHOW_NEWS") {385 this.sendNotification("SHOW_NEWS");386 }387 // MMM-Voice-Commands sends notification to MMM-PETFINDER to HIDE388 else if (notification === "HIDE_PETFINDER") {389 this.sendNotification("HIDE_PETFINDER");390 }391 // MMM-Voice-Commands sends notification to MMM-PETFINDER to SHOW392 else if (notification === "SHOW_PETFINDER") {393 this.sendNotification("SHOW_PETFINDER");394 }395 // MMM-Voice-Commands sends notification to MMM-FMI to HIDE396 else if (notification === "HIDE_PHONE") {397 this.sendNotification("HIDE_PHONE");398 }399 // MMM-Voice-Commands sends notification to MMM-FMI to SHOW400 else if (notification === "SHOW_PHONE") {401 this.sendNotification("SHOW_PHONE");402 }403 // MMM-Voice-Commands sends notification to MMM-ImageSlideshow to HIDE404 else if (notification === "HIDE_PICTURES") {405 this.sendNotification("HIDE_PICTURES");406 }407 // MMM-Voice-Commands sends notification to MMM-ImageSlideshow to SHOW408 else if (notification === "SHOW_PICTURES") {409 this.sendNotification("SHOW_PICTURES");410 }411 // MMM-Voice-Commands sends notification to MMM-PilotWX to HIDE412 else if (notification === "HIDE_PILOTS") {413 this.sendNotification("HIDE_PILOTS");414 }415 // MMM-Voice-Commands sends notification to MMM-PilotWX to SHOW416 else if (notification === "SHOW_PILOTS") {417 this.sendNotification("SHOW_PILOTS");418 }419 // MMM-Voice-Commands sends notification to MMM-AfterShip to HIDE420 else if (notification === "HIDE_SHIPPING") {421 this.sendNotification("HIDE_SHIPPING");422 }423 // MMM-Voice-Commands sends notification to MMM-AfterShip to SHOW424 else if (notification === "SHOW_SHIPPING") {425 this.sendNotification("SHOW_SHIPPING");426 }427 // MMM-Voice-Commands sends notification to MMM-ISS to HIDE428 else if (notification === "HIDE_STATION") {429 this.sendNotification("HIDE_STATION");430 }431 // MMM-Voice-Commands sends notification to MMM-ISS to SHOW432 else if (notification === "SHOW_STATION") {433 this.sendNotification("SHOW_STATION");434 }435 // MMM-Voice-Commands sends notification to MMM-PC-Stats to HIDE436 else if (notification === "HIDE_STATS") {437 this.sendNotification("HIDE_STATS");438 }439 // MMM-Voice-Commands sends notification to MMM-PC-Stats to SHOW440 else if (notification === "SHOW_STATS") {441 this.sendNotification("SHOW_STATS");442 }443 // MMM-Voice-Commands sends notification to MMM-Sudoku to HIDE444 else if (notification === "HIDE_SUDOKU") {445 this.sendNotification("HIDE_SUDOKU");446 }447 // MMM-Voice-Commands sends notification to MMM-Sudoku to SHOW448 else if (notification === "SHOW_SUDOKU") {449 this.sendNotification("SHOW_SUDOKU");450 }451 // MMM-Voice-Commands sends notification to MMM-SunRiseSet to HIDE452 else if (notification === "HIDE_SUNRISE") {453 this.sendNotification("HIDE_SUNRISE");454 }455 // MMM-Voice-Commands sends notification to MMM-SunRiseSet to SHOW456 else if (notification === "SHOW_SUNRISE") {457 this.sendNotification("SHOW_SUNRISE");458 }459 // MMM-Voice-Commands sends notification to MMM-SORT to HIDE460 else if (notification === "HIDE_TIDES") {461 this.sendNotification("HIDE_TIDES");462 }463 // MMM-Voice-Commands sends notification to MMM-SORT to SHOW464 else if (notification === "SHOW_TIDES") {465 this.sendNotification("SHOW_TIDES");466 }467 // MMM-Voice-Commands sends notification to MMM-EventHorizon to HIDE468 else if (notification === "HIDE_TIMER") {469 this.sendNotification("HIDE_TIMER");470 }471 // MMM-Voice-Commands sends notification to MMM-EventHorizon to SHOW472 else if (notification === "SHOW_TIMER") {473 this.sendNotification("SHOW_TIMER");474 }475 // MMM-Voice-Commands sends notification to MMM-ATM to HIDE476 else if (notification === "HIDE_TRIVIA") {477 this.sendNotification("HIDE_TRIVIA");478 }479 // MMM-Voice-Commands sends notification to MMM-ATM to SHOW480 else if (notification === "SHOW_TRIVIA") {481 this.sendNotification("SHOW_TRIVIA");482 }483 // MMM-Voice-Commands sends notification to MMM-Voice-Commands to HIDE484 else if (notification === "HIDE_VOICE") {485 this.hide(1000);486 }487 // MMM-Voice-Commands sends notification to MMM-Voice-Commands to SHOW488 else if (notification === "SHOW_VOICE") {489 this.show(1000);490 }491 // MMM-Voice-Commands sends notification to MMM-BMW-DS to HIDE492 else if (notification === "HIDE_WEATHER") {493 this.sendNotification("HIDE_WEATHER");494 }495 // MMM-Voice-Commands sends notification to MMM-BMW-DS to SHOW496 else if (notification === "SHOW_WEATHER") {497 this.sendNotification("SHOW_WEATHER");498 }499 // MMM-Voice-Commands sends notification to MMM-EarthWinds to HIDE500 else if (notification === "HIDE_WIND") {501 this.sendNotification("HIDE_WIND");502 }503 // MMM-Voice-Commands sends notification to MMM-EarthWinds to SHOW504 else if (notification === "SHOW_WIND") {505 this.sendNotification("SHOW_WIND");506 }507 }508 });509 }510 }511 },512 addCommands: function(commands) {513 annyang.abort();514 annyang.addCommands(commands);515 annyang.start();516 },517 removeCommands: function(commands) {518 annyang.abort();519 if (typeof commands === "object")...
testSendNotification.js
Source:testSendNotification.js
...59 server.on('listening', listening);60 }61 test('send/receive string', function(done) {62 startServer('hello', function() {63 webPush.sendNotification('https://127.0.0.1:50005', 0, urlBase64.encode(userPublicKey), 'hello').then(function() {64 assert(true, 'sendNotification promise resolved');65 }, function() {66 assert(false, 'sendNotification promise rejected')67 }).then(done);68 }, 0);69 });70 test('send/receive buffer', function(done) {71 startServer('hello', function() {72 webPush.sendNotification('https://127.0.0.1:50005', 0, urlBase64.encode(userPublicKey), new Buffer('hello')).then(function() {73 assert(true, 'sendNotification promise resolved');74 }, function() {75 assert(false, 'sendNotification promise rejected')76 }).then(done);77 }, 0);78 });79 test('send/receive empty message', function(done) {80 startServer('', function() {81 webPush.sendNotification('https://127.0.0.1:50005', 0, urlBase64.encode(userPublicKey), '').then(function() {82 assert(true, 'sendNotification promise resolved');83 }, function() {84 assert(false, 'sendNotification promise rejected')85 }).then(done);86 }, 0);87 });88 test('send/receive without message', function(done) {89 startServer(undefined, function() {90 webPush.sendNotification('https://127.0.0.1:50005').then(function() {91 assert(true, 'sendNotification promise resolved');92 }, function() {93 assert(false, 'sendNotification promise rejected');94 }).then(done);95 });96 });97 test('send/receive without message with TTL', function(done) {98 startServer(undefined, function() {99 webPush.sendNotification('https://127.0.0.1:50005', 5).then(function() {100 assert(true, 'sendNotification promise resolved');101 }, function() {102 assert(false, 'sendNotification promise rejected');103 }).then(done);104 }, 5);105 });106 test('send/receive string with TTL', function(done) {107 startServer('hello', function() {108 webPush.sendNotification('https://127.0.0.1:50005', 5, urlBase64.encode(userPublicKey), 'hello').then(function() {109 assert(true, 'sendNotification promise resolved');110 }, function() {111 assert(false, 'sendNotification promise rejected');112 }).then(done);113 }, 5);114 });115 test('promise rejected when it can\'t connect to the server', function(done) {116 webPush.sendNotification('https://127.0.0.1:50005').then(function() {117 assert(false, 'sendNotification promise resolved');118 }, function() {119 assert(true, 'sendNotification promise rejected');120 }).then(done);121 });122 test('promise rejected when the response status code is unexpected', function(done) {123 startServer(undefined, function() {124 webPush.sendNotification('https://127.0.0.1:50005').then(function() {125 assert(false, 'sendNotification promise resolved');126 }, function() {127 assert(true, 'sendNotification promise rejected');128 }).then(done);129 }, undefined, 404);130 });131 test('send/receive GCM', function(done) {132 var httpsrequest = https.request;133 https.request = function(options, listener) {134 options.hostname = '127.0.0.1';135 options.port = '50005';136 options.path = '/';137 return httpsrequest.call(https, options, listener);138 }139 webPush.setGCMAPIKey('my_gcm_key');140 startServer(undefined, function() {141 webPush.sendNotification('https://android.googleapis.com/gcm/send/someSubscriptionID').then(function() {142 assert(true, 'sendNotification promise resolved');143 }, function() {144 assert(false, 'sendNotification promise rejected');145 }).then(done);146 }, undefined, 200, true);147 });...
send-notification.component.ts
Source:send-notification.component.ts
...134 'userType': this.sendNotification.userType,135 'vendorCode': this.sendNotification.vendorCode,136 'vendorCode2': this.sendNotification.vendorCode2137 }138 this.salesService.sendNotification(notification).subscribe(res => {139 this.toastr.success('Sent Successfully !!');140 this.clearValues();141 this.spinner.hide();142 }, err => {143 this.spinner.hide();144 });145 }146 selectedTargetUser(res) {147 this.selectedTargetUserstr = res.title;148 }149 selectedSendUsing(res) {150 this.selectedSendUsingStr = res.title;151 if (res.title == 'Pin Code') {152 this.isPincode = true;...
Using AI Code Generation
1import { useAuth } from '@redwoodjs/auth'2import { useMutation } from '@redwoodjs/web'3import { navigate, routes } from '@redwoodjs/router'4import { toast } from '@redwoodjs/web/toast'5 mutation SendNotificationMutation($input: SendNotificationInput!) {6 sendNotification(input: $input) {7 }8 }9const SendNotification = () => {10 const { currentUser } = useAuth()11 const [sendNotification, { loading, error }] = useMutation(12 {13 onCompleted: () => {14 toast.success('Notification sent')15 navigate(routes.notifications())16 },17 }18 const onSubmit = (input) => {19 sendNotification({ variables: { input } })20 }21 return (22 currentUser={currentUser}23 onSubmit={onSubmit}24 loading={loading}25 error={error}26}
Using AI Code Generation
1const { sendNotification } = require('@redwoodjs/api')2const { sendNotification } = require('@redwoodjs/api')3const { sendNotification } = require('@redwoodjs/api')4const { sendNotification } = require('@redwoodjs/api')5const { sendNotification } = require('@redwoodjs/api')6const { sendNotification } = require('@redwoodjs/api')7const { sendNotification } = require('@redwoodjs/api')8const { sendNotification } = require('@redwoodjs/api')9const { sendNotification } = require('@redwoodjs/api')10const { sendNotification } = require('@redwoodjs/api')11const { sendNotification } = require('@redwoodjs/api')12const { sendNotification } = require('@redwoodjs/api')13const { sendNotification } = require('@redwoodjs/api')14const { sendNotification } = require('@redwoodjs/api')15const { sendNotification } = require('@redwoodjs/api')16const { sendNotification } = require('@redwoodjs/api')17const { sendNotification } = require('@redwoodjs/api')
Using AI Code Generation
1import { sendNotification } from '@redwoodjs/api'2export const handler = async () => {3 await sendNotification({4 })5}6### `sendNotification(options)`7### `sendNotificationToTopic(topic, options)`
Using AI Code Generation
1import { sendNotification } from '@redwoodjs/api'2export const handler = async () => {3 await sendNotification({4 })5}6import { useNotifications } from '@redwoodjs/web'7const HomePage = () => {8 const { sendNotification } = useNotifications()9 return (10 onClick={() =>11 sendNotification({12 })13 }14}15- [NotificationsProvider](#notificationsprovider)16- [useNotifications](#usenotifications)17- [sendNotification](#sendnotification)18- [NotificationContext](#notificationcontext)19| defaultActions | `object` | The default actions for notifications. See [Notification Actions](#notification-actions) for more information. |20import { NotificationsProvider } from '@redwoodjs/web/notifications'21ReactDOM.render(
Using AI Code Generation
1const { sendNotification } = require('@redwoodjs/api')2const sendPushNotification = async () => {3 const notification = {4 data: { key1: 'value1' },5 }6 await sendNotification(notification)7}8sendPushNotification()
Using AI Code Generation
1import { sendNotification } from '@redwoodjs/api'2export const handler = async () => {3 await sendNotification('my-event', { message: 'Hello from the API!' })4}5import { useNotifications } from '@redwoodjs/web'6const HomePage = () => {7 const sendNotification = useNotifications()8 const handleClick = () => {9 sendNotification('my-event', { message: 'Hello from the client!' })10 }11 return (12 <button onClick={handleClick}>Send Notification</button>13}14import { useNotifications } from '@redwoodjs/web'15const Notifications = () => {16 const sendNotification = useNotifications()17 useEffect(() => {18 sendNotification('my-event', { message: 'Hello from the client!' })19 }, [])20}21import { NotificationsProvider } from '@redwoodjs/web'22const App = () => {23 return (24 <FatalErrorBoundary page={FatalErrorPage}>25}26import { NotificationsProvider } from '@redwoodjs/web'27ReactDOM.render(28 <FatalErrorBoundary page={FatalErrorPage}>
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!