Integrate Alan.app with flutter

  • After login you will be redirect to the studio.alan.app/projects
  • Now you will see a create voice assistant button, when you click on it you will see like this.
  • Here we can write script in two ways inform of intent,play or question,reply
  • Intent() / question() is the basic commonly used function to describe by a user commands.
    Intent is basically of two parts 1) Pattern 2) Action
    Action will be executed when Pattern is matched.
    Play() / reply() is predefined function that is used to reply the message or command in the form of JSON Object (key:value pairs) for your questions.
  • Now write some simple script and play with it.
question(
'What is your name',
reply('I am Alex','I a new assistant called Alex')
)
question(
'Tell me some jokes',
reply("What did one plate say to his friend? Tonight, dinner's on me!",
"I tried to sure the airport for misplacing my luggage. I lost my case",
"What did one traffic light say to the other? Stop looking! I am changing!",
"What's red and moves up and down? A tomato in an elevator!",
"My girlfriend treats me like God. She ignores my existence and only talks to me when she needs something."
)
)
  • In the Script the reply will give you a random text which is under comma separated text values.
flutter create interate_alan_app
  • Follow the package :
import 'package:alan_voice/alan_voice.dart';
  • Now create a default method called setUpAlan() in your statefulwidget class and add this:
setUpalan() {
AlanVoice.addButton("***KEY***/stage",buttonAlign: AlanVoice.BUTTON_ALIGN_RIGHT);
}
@override
void initState() {
super.initState();
setUpalan();
}
  • If your Platform type is Android go to android/app/build.gradle file and change the minSdkVersion to 21 and for IOS no need to change.
  • Add new questions with answer and start try it in your mobile app by asking to alan.
  • Add basic code for those both files which display some text.
  • Write some queries ‘ what to do when you ask to navigate to other page’, Now in p.play we need to add key:value pairs like command:Aboutus or route:/main
AlanVoice.callbacks.add((command) => _handleCmd(command.data));
_handleCmd(Map<String, dynamic> res) {}
switch (res["command"]) {
case "Aboutus":
print('About us');
break;
default:
print("Nothing");
break;
}
Navigator.push(
context, MaterialPageRoute(builder: (context) => AboutUs()));

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store