Jovo FrameWork: this.followUpState doesn't do its job like it's supposed to - alexa

I have this intent
'NameIntent': function(name) {
let speech = 'Hello ' + name.value + ', nice to meet you! which Radio do you want me to play? ;
this.followUpState('MakeSureEnterRadioIntentState').ask(speech);
},
which gets triggered with the utterance {name}. Example: User says: SAM
The stateIntent code is as follows:
The PlayRadioIntent get triggered with the utterance {radioName}. Example: User says: Mosaique
'MakeSureEnterRadioIntentState': { //TO solve this problem: IN CASE USER SAYS MOSAIQUE AFTER NAMEINTENT ALEXA WILL INTERPRET MOSAIQUE AS A NAME AND WILL REENTER NAMEINTENT
'PlayRadioIntent': function(channel) {
this.tell("The radioName is" + channel.value);}
The problem I tried to resolve with this state:
ALEXA: Hello Sam nice to meet you! which Radio do you want me to play? ;
USER: Mosaique
//Mosaique is a radio name
ALEXA: Hello Mosaique nice to meet you! which Radio do you want me to play? ;
//ALEXA interprets mosaique as a name instead of a radioName and reenters the NameIntent. I thought using states would be perfect for resolving this confusion. and they SHOULD. But, they aren't and I do not really understand why.
HELP?

The Jovo Routing works as follows if it is in a state: (1) Look if the intent is found in the state, if not (2) look if "Unhandled" is defined in the state, if not (3) look if the intent can be found outside the state, if not (4) look if "Unhandled" is defined outside the state, if not (5) throw an error.
In your case, "NameIntent" can't be found in the state, so it goes to the global (stateless) "NameIntent". To stay in the state, you can add an "Unhandled" intent that acts as a "catch all" for any intent that can't be found in there.
Take a look at this section to learn more about states and Unhandled: https://www.jovo.tech/blog/p2s5-introduction-to-states/#unhandled-intent

Related

Trying to do a dm command with msg.mentions.users.first, but it's not working

if(msg.content.startsWith("&%walcome")){
const mentionid = bot.users.cache.get(`${msg.mentions.users.first().id}`)
const up = new Discord.MessageEmbed()
.setColor('#C8CAF9')
.setTitle('Sup')
.setThumbnail(`${msg.mentions.users.first().displayAvatarURL()}`)
.setDescription(`Sup **${msg.mentions.user.first().tag}**, be welcome to MFPA Official Discord Community. If you joined withouht knowing wth is this server, I will explain: this is the official server of the series with the same new, that is available on youtube (https://www.youtube.com/channel/UCWZRrkidNF5Se8fkgGzoxgg)`)
.addFields(
{name: 'Fun in server', value: 'That is right, dear new member, you can actually have fun in this channel! We have some custom emojis, events, chat (sometimes is dead but eh-). But!, first of all, do not forget to go to #verify (823564914605686844) to get access to the server'},
{name: 'Specific Announcements', value: 'You can receive specific announcements (Faded Pics, Betro Ideas and Dani Sounds) if you are interested in the whole production of the series'},
{name: 'If you need help, just dm a staff member', value: 'Thats right, if you need help, you can contact one of the Staff Team member, they will reply when available'}
)
.setFooter(`Sent by ${msg.author.tag}, bot made by dani bear#3606`, `${msg.author.displayAvatarURL()}`)
mentionid.send(up)
}
})
So, this code is not working, and I don't know why. The error is Cannot read property 'first' of undefined, but I already used this and it worked-
If you could help I would be grateful!
You have a typo in .setDescription('Sup **${msg.mentions.user.first().tag...)}'.Its msg.mentions.users.first()(Missed an 's' in 'users'). Also, if you are going to use the mentioned User object again and again, store then in a variable, and then access the properties of that.

How to keep track of what question user is responding to?

Some questions my messenger chatbot is asking require textual input. In the button template I can set the payload so I know what exactly user chosen and handle it based on that. But with textual responses I need to filter if user answer is somehow related to "Change address, Billing, Returns, etc." For example:
bot-question: What is your new phone number?
user-answer: +123 123 12345
And now in the back-end I'm doing this:
if(user-answer in_array('billing keywords') {
// code
} elseif (user-answer in_array('delivery keywords')) {
// code
} elseif (user-answer in_array('payments keywords')) {
// code
} elseif (user-answer in_array('change-phone-number keywords')) {
// Finally got where I wanted 🎉😒
}
Isn't it possible to somehow add some tag to bot-question, so I would already know that the answer will be related to change-phone-number keywords? For example like this:
"template_type" => "text",
"text" => "What is your new phone number?",
"payload" => "changing_phone_number"
In the end it was impossible to get some postback from a normal text message, so what I did, I created additional columns:
expecting_billing_info
expecting_phone_number_update
etc.
And I set it to 0 by default, but when bot asks a question like:
Would you like to change your phone number?
I set it to 1 and when user types it in I do:
if (expecting_phone_number_update == 1) {
// 1. get the message
// 2. Check if it's correct phone number format
// 3. Reply based on 2. and update phone number
} elseif (expecting_billing_info == 1) {
// ...
}
This is not perfectly clean solution, but it does the work. Let's hope messenger will release this postback feature one day for normal messages as well! :)

giving a string slot in Amazon alexa

I'm new to alexa. I learnt and started to build a weather app.
right now I'm able to get weather data, but on the below condition,
I've craeated a custom slot(LIST_OF_CITIES) to hold Cities as below.
{
"intents": [
{
"intent": "WeatherIntent",
"slots": [
{
"name": "city",
"type": "LIST_OF_CITIES"
}
]
},
{
"intent": "AMAZON.HelpIntent"
},
]
}
and in my custom slot I gave as below.
Type Values
LIST_OF_CITIES Hyderabad | pune | london
and below are my Utterances
WeatherIntent give me {city} climate
WeatherIntent {city}
WeatherIntent what's the climate in {city}
WeatherIntent what's the weather in {city}
WeatherIntent {city}
when I run my program using any of the three cities mentioned in the above table, I'm able to get the correct. If I use anything apart from the above, it is sending back value as -4.
If I want to get tempreature of some other city, I need to add that city in the slot list.
Please let me know how can I get the vaues dynamically, I mean with out depending on the LIST_OF_CITIES, If I enter a city name, it should send back the result.
Also I tried adding type as LITERAL and also as AMAZON.LITERAL. When I saved it, I get the exception as
Error: There was a problem with your request: Unknown slot name '{city}'. Occurred in sample 'WeatherIntent get me weather of {city}' on line 1.
Please let me know where am I going wrong and how can I fix this.
Thanks
Amazon provides some default list Slot Types for cities or even regions. E.g.
AMAZON.US_CITY
AMAZON.AT_CITY
AMAZON.DE_REGION
...
You can use these as type when defining your custom slot.
First, don't use LITERAL - it is deprecated and isn't even supported at all outside US region.
And no, you can't manage the list of words dynamically.
Alexa will try to match what the user says with your LIST_OF_CITIES, and will try to return one of those words, but might return something else if it can't match one of those (as you have seen).
There are some custom slot types for cities that you can use and build off of, see here:
https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interaction-model-reference#h2_custom_syntax
But that probably won't work for you since each of them is just one country, so you will need to build your own list of cities (in your LIST_OF_CITIES).

React/Flux app data structure

i'm building an Gmail-like email browser client app prototype and i need a little help/advice structuring my React/Flux app. I decided to use pure Flux to get a better idea of how it works.
It's a simple email client with a list of letters, grouped by folders and tags and an ability to add letters to favorites.
So, i have a LettersStore containing an array of letters. The single letter data object looks something like this
{
id: 0,
new: true, //unread
checked: false,
starred: false,
folder: "inbox", //could be 'sent', 'spam', 'drafts'
sender: "Sender Name",
subject: "Re:",
snippet: "Hello there, how are you...",
body: "Hello there, how are you doing, Mike?",
date: "02.19.2016 16:30",
tags:["personal", "urgent"]
}
So what i'm trying to achieve is to let users navigate through folders (inbox, sent, drafts, spam) and filters (starred, tag, etc.)
In both folders and filters there has to be a way to select (check) some/all letters. The view state depends on how many letters are selected (the Select-all checkbox update, just like on Gmail). When the user selects a letter, the Flux action is being triggered and the state of the app updates.
The controller-view on top of the app does all the calls to the LettersStore public methods and passes the data down as props, but i'm not sure, what public methods the LettersStore should have. Currently it has:
emitChange()
addChangeListener()
removeChangeListener()
getAll() //returns array
areSomeLettersInFolderChecked(folderName) //returns bool
areAllLettersInFolderChecked(folderName) //returns bool
countNewLettersInAllFolders() //returns object
This works ok with folders, but when it comes to filters, it doesn't make sense anymore, since a starred letter is in some folder, and i feel like it's not the right thing to add specific methods like areSomeLettersInFilterChecked(filterType) etc.
Also, just like in Gmail, there has to be a way to select letter in the "Starred" filter, which belongs to the "Inbox" folder, then navigate to "Inbox" folder and keep that letter selected.
Maybe i should move the areSomeLettersInFolderChecked-like stuff to the component level?
I'm sure here has to be a proper way of doing it. Thanks in advance!
Rather than trying to encapsulate all the possible states and filters into your letter objects, keep it dumb. Normalize it and use supporting data structures to represent the other characteristics.
I'd strip it down to just the following properties:
{
id: 0,
sender: "Sender Name",
subject: "Re:",
snippet: "Hello there, how are you...",
body: "Hello there, how are you doing, Mike?",
date: "02.19.2016 16:30",
tags:["personal", "urgent"]
}
Your LetterStore can stay the same, or alternatively you could use an object or map to store letters against their id's for quick lookups later.
Now we need to represent the properties we removed from the message.
We can use individual sets to determine whether a message belongs to the new, checked and starred categories.
For instance, to star a message, just add it's id to the starred set.
var starred = new Set();
starred.add(message.id);
You can easily check whether a message is starred later on.
function isStarred(message) {
return starred.has(message.id);
}
The pattern would be the same for checked and unread.
To represent folders you probably want to use a combination of objects and sets.
var folders = {
inbox: new Set(),
sent: new Set(),
spam: new Set(),
drafts: new Set()
}
Simplifying your structures into these sets makes designing queries quite easy. Here are some examples of the methods you talked about implemented with sets.
function checkAll() {
messages.forEach(function(message) {
checked.add(message.id);
});
return checked;
}
function isChecked(message) {
return checked.has(message.id);
}
function inFolder(name, message) {
return folders[name].has(message.id);
}
// is message checked and in inbox
if(isChecked(message) && inFolder('inbox', message)) {
// do something
}
It becomes easy to construct complex queries, simply by checking whether messages belong to multiple sets.

change event not getting triggered with poltergeist

I have 2 dropdowns and on change of first am prepopulating the second dropdown(which is been done in backbone).
events: ->
'change #client_id': 'selectedClientChange'
selectedClientChange: (ev) ->
#populateGroups $(ev.target.selectedOptions).val()
Written capybara specs for the same with poltergeist but change event is not getting triggered for some reason and spec is getting failed.
scenario 'it should populate the groups automatically', js: true, speed: :slow do
click_link 'New Item'
find('#name').set('Sample Item')
page.execute_script("$('#client_id').val('testing').trigger('change')")
select "#{client.name}", from: "client_id"
groups = find('#group_id').all('option').collect(&:text)
expect(groups.count).to eq 1
expect(groups).to include pg.name
end
Can someone tell me how to solve this.
Without details about the error you're getting this is mostly a guess - It's possible you're getting the groups before the change event from the select actually updates them. You'd be better off using the have_select matcher since it will retry for a time to see if the field changes to match the requirements
select "#{client.name}", from: "client_id"
expect(page).to have_select('group_id', options: [pg.name])
Ah sorry everyone. I see that there is an issue with poltergeist which I found here https://github.com/teampoltergeist/poltergeist/issues/204. Thanks alot!

Resources