newuser-98138dc5-2198-4f44-91e6-3d0d63dd14b6 avatar image

Start an Alexa Interaction from the Backend

I am writing my first Alexa's Skill with the aim of interacting with a robot by providing voice input and also allowing the robot to send back messages through the Alexa interface. I'm using the Flask-Ask Python extension to write a local backend, using ngrok to estabilish the http comunication and ROS to communicate with the robot.

I create both launch and stop intents and also a personal one in wich I ask Alexa to move the robot.

What I need to do now is create a function that allows me to communicate a message using the alexa speak output, without user interaction; For example when a custom if condition is triggered, I want Alexa to play a sample message:

if condition == True:
    def advise_function():
        sample_message = 'Messaggio di avviso'
        return statement(sample_message)

This is the actual code (for reference):

#!/usr/bin/env python
import os
import rospy
import threading
import requests
import time

from flask import Flask
from flask_ask import Ask, question, statement, session
from std_msgs.msg import String, Float64

#---------------------------------------------- FLASK & ROS INIZIALIZATION ---------------------------------------------#

app = Flask(__name__)
ask = Ask(app, "/")

# ROS node, publisher, and parameter. The node is started in a separate thread to avoid conflicts with Flask.
# The parameter *disable_signals* must be set if node is not initialized in the main thread.
threading.Thread(target=lambda: rospy.init_node('alexa_ros_node', disable_signals=True)).start()
direction_publisher = rospy.Publisher('alexa/direction', String, queue_size=100)
length_publisher = rospy.Publisher('alexa/lenght', Float64, queue_size=100)
NGROK = rospy.get_param('/ngrok', None)

#------------------------------------------------------- INTENTS -------------------------------------------------------#

# LaunchIntent -> Avvio dell'applicazione: "Apri nodo ros"
def launch():
    welcome_message = 'Benvenuto nel nodo di controllo ROS. Come posso aiutarti?'
    return question(welcome_message)

# MuoviRobotIntent: "Muovi il robot"
@ask.intent('MuoviRobotIntent', default={'direzione':None, 'lunghezza':None})
def move_robot_function(direzione, lunghezza):
    return statement('Ho pubblicato direzione e lunghezza sul topic ROS: {0} di {1} metri.'.format(direzione, lunghezza))

# StopIntent -> Uscita dall'applicazione: "Stop / Esci..."
def session_ended():
    return "{}", 200

# ngrok app running
if __name__ == '__main__':
    if NGROK:
        print 'NGROK mode'['ROS_IP'], port=5000)
        print 'Manual tunneling mode'
        dirpath = os.path.dirname(__file__)
        cert_file = os.path.join(dirpath, '../config/ssl_keys/certificate.pem')
        pkey_file = os.path.join(dirpath, '../config/ssl_keys/private-key.pem')['ROS_IP'], port=5000,
                ssl_context=(cert_file, pkey_file))
skill builderinteraction modelskill messaging
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers