Play sound and create new dialog using hermes javascript

Hi Guys,

I’m trying to setup a time for playing a sound using tts. Is the time reached the sound should be played. I’ve already registered the sound but it’s not clear to me how I can accomplish this by using hermes javascript.

This is my intent which is setting up the sound and time.

withHermes(hermes => {
			const dialog = hermes.dialog()
			const tts = hermes.tts()
			tts.publish('register_sound', {
				soundId: '123456',
				wavSound: wavBuffer.toString('base64')
			})    
dialog.flow('bozor:newToDo', (msg, flow) => {
    			if (todoSlot instanceof Object && timeSlot instanceof Object) {
    				flow.end()
    				const dateReceived = timeSlot.value.value
    				const time = moment(dateReceived,moment.HTML5_FMT.DATETIME_LOCAL_SECONDS)
    				const minutes = time.minutes()
    				const hours = time.hours()
    				const date = time.date()
    					if (minutes === 0) {
    						this.setNotification(minutes, hours)
    						return 'Ok ich notiere das Todo: ' 
    					} else {
    						return 'Ok ich notiere das Todo: ' + todoSlot.value.value + 'und erinnere dich um ' + hours + 'Uhr' + minutes, this.setNotification(minutes, hours, dialog)
    					}

Some curly braces are missing in this snippet.
The setNotification function:

setNotification(minute, hour, dialog) {
		let j = schedule.scheduleJob(minute + " " + hour + " * * *", () => {
			console.log('The answer to life, the universe, and everything!')

			dialog.publish('hermes/audioServer/default/playBytes/123456')

		});
	}

When I’m returning the immediately and in the function itself it is returning return '[[sound:123456]]' everything is just working fine.

Any hint on how to achieve this.

Thanks in advance

Well, after some more research I’ve solved it myself :slight_smile:

In case someone struggles as well.

put this code into the notification function and it will work:

dialog.publish('start_session', {
				siteId: 'default',
				init: { type: 'notification', text: '[[sound:123456]]' }
		}) 

Cheers

1 Like