Repeating Dialogflow Intent Until Condition is Met












0















I am using Python and the Dialogflow V2 API. I would like to know how to reprompt an intent until a condition is met using Python Flask as the fulfillment. I am filling slots and then running an SQL query to verify the user's identity. If the query returns false (there is no identity that exists in the database), then I would like to rerun the intent until the condition is met (userId is found).



I have tried looking at the JS documentation, but cannot find any Python documentation for accomplishing the feat.










share|improve this question

























  • Hm. I think I might have a solution but don't know how to implement it. Is there a way to trigger a fallback intent if a query run in the previous intent does not satisfy a condition? EX: userId is not found in the database after a user gives their name.

    – JAWS007
    Dec 29 '18 at 23:57
















0















I am using Python and the Dialogflow V2 API. I would like to know how to reprompt an intent until a condition is met using Python Flask as the fulfillment. I am filling slots and then running an SQL query to verify the user's identity. If the query returns false (there is no identity that exists in the database), then I would like to rerun the intent until the condition is met (userId is found).



I have tried looking at the JS documentation, but cannot find any Python documentation for accomplishing the feat.










share|improve this question

























  • Hm. I think I might have a solution but don't know how to implement it. Is there a way to trigger a fallback intent if a query run in the previous intent does not satisfy a condition? EX: userId is not found in the database after a user gives their name.

    – JAWS007
    Dec 29 '18 at 23:57














0












0








0








I am using Python and the Dialogflow V2 API. I would like to know how to reprompt an intent until a condition is met using Python Flask as the fulfillment. I am filling slots and then running an SQL query to verify the user's identity. If the query returns false (there is no identity that exists in the database), then I would like to rerun the intent until the condition is met (userId is found).



I have tried looking at the JS documentation, but cannot find any Python documentation for accomplishing the feat.










share|improve this question
















I am using Python and the Dialogflow V2 API. I would like to know how to reprompt an intent until a condition is met using Python Flask as the fulfillment. I am filling slots and then running an SQL query to verify the user's identity. If the query returns false (there is no identity that exists in the database), then I would like to rerun the intent until the condition is met (userId is found).



I have tried looking at the JS documentation, but cannot find any Python documentation for accomplishing the feat.







python python-3.x flask dialogflow dialogflow-fulfillment






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 29 '18 at 5:28







JAWS007

















asked Dec 29 '18 at 2:55









JAWS007JAWS007

1327




1327













  • Hm. I think I might have a solution but don't know how to implement it. Is there a way to trigger a fallback intent if a query run in the previous intent does not satisfy a condition? EX: userId is not found in the database after a user gives their name.

    – JAWS007
    Dec 29 '18 at 23:57



















  • Hm. I think I might have a solution but don't know how to implement it. Is there a way to trigger a fallback intent if a query run in the previous intent does not satisfy a condition? EX: userId is not found in the database after a user gives their name.

    – JAWS007
    Dec 29 '18 at 23:57

















Hm. I think I might have a solution but don't know how to implement it. Is there a way to trigger a fallback intent if a query run in the previous intent does not satisfy a condition? EX: userId is not found in the database after a user gives their name.

– JAWS007
Dec 29 '18 at 23:57





Hm. I think I might have a solution but don't know how to implement it. Is there a way to trigger a fallback intent if a query run in the previous intent does not satisfy a condition? EX: userId is not found in the database after a user gives their name.

– JAWS007
Dec 29 '18 at 23:57












1 Answer
1






active

oldest

votes


















1














In the fulfillment, if condition is false, just reply with the same question like Sorry this username does not exist, please enter the username again.



if not username:
res = json.dumps({
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


If you have some input context for the intent as well, then you need to set he context from the fulfillment as well.



req = request.get_json()
if not username:
res = json.dumps({
"outputContexts": [
{
"name": "{}/contexts/ask-username".format(req['session']),
"lifespanCount": 1,
},
],
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


EDIT:

To reset a parameter value, include the parameter in the output context as well in the webhook, and set #context.parameter as the default value of parameter in dialogflow console.
Documentation for setting default value of entity from context.



 "outputContexts": [
{
"name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/ask-username",
"lifespanCount": 1,
"parameters": {
"foo": ""
}
}
]


default value



Hope it helps.






share|improve this answer


























  • Thanks @sid8491 Is there a way to "go back"/clear a slot and get the next response from the user if the condition is not yet met? Similar to Rasa NLU's UserUtteranceReverted()?

    – JAWS007
    Dec 29 '18 at 23:12













  • @JAWS007 yes, you can include the slot in the output context and set their value to NULL, in the intent set default value of slot to #context.slot

    – sid8491
    Dec 30 '18 at 6:40











  • Awesome @sid8491. Is there perhaps some documentation for this? Thanks.

    – JAWS007
    Dec 31 '18 at 4:55













  • @JAWS007 here you go

    – sid8491
    Jan 2 at 6:39













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53966323%2frepeating-dialogflow-intent-until-condition-is-met%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In the fulfillment, if condition is false, just reply with the same question like Sorry this username does not exist, please enter the username again.



if not username:
res = json.dumps({
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


If you have some input context for the intent as well, then you need to set he context from the fulfillment as well.



req = request.get_json()
if not username:
res = json.dumps({
"outputContexts": [
{
"name": "{}/contexts/ask-username".format(req['session']),
"lifespanCount": 1,
},
],
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


EDIT:

To reset a parameter value, include the parameter in the output context as well in the webhook, and set #context.parameter as the default value of parameter in dialogflow console.
Documentation for setting default value of entity from context.



 "outputContexts": [
{
"name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/ask-username",
"lifespanCount": 1,
"parameters": {
"foo": ""
}
}
]


default value



Hope it helps.






share|improve this answer


























  • Thanks @sid8491 Is there a way to "go back"/clear a slot and get the next response from the user if the condition is not yet met? Similar to Rasa NLU's UserUtteranceReverted()?

    – JAWS007
    Dec 29 '18 at 23:12













  • @JAWS007 yes, you can include the slot in the output context and set their value to NULL, in the intent set default value of slot to #context.slot

    – sid8491
    Dec 30 '18 at 6:40











  • Awesome @sid8491. Is there perhaps some documentation for this? Thanks.

    – JAWS007
    Dec 31 '18 at 4:55













  • @JAWS007 here you go

    – sid8491
    Jan 2 at 6:39


















1














In the fulfillment, if condition is false, just reply with the same question like Sorry this username does not exist, please enter the username again.



if not username:
res = json.dumps({
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


If you have some input context for the intent as well, then you need to set he context from the fulfillment as well.



req = request.get_json()
if not username:
res = json.dumps({
"outputContexts": [
{
"name": "{}/contexts/ask-username".format(req['session']),
"lifespanCount": 1,
},
],
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


EDIT:

To reset a parameter value, include the parameter in the output context as well in the webhook, and set #context.parameter as the default value of parameter in dialogflow console.
Documentation for setting default value of entity from context.



 "outputContexts": [
{
"name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/ask-username",
"lifespanCount": 1,
"parameters": {
"foo": ""
}
}
]


default value



Hope it helps.






share|improve this answer


























  • Thanks @sid8491 Is there a way to "go back"/clear a slot and get the next response from the user if the condition is not yet met? Similar to Rasa NLU's UserUtteranceReverted()?

    – JAWS007
    Dec 29 '18 at 23:12













  • @JAWS007 yes, you can include the slot in the output context and set their value to NULL, in the intent set default value of slot to #context.slot

    – sid8491
    Dec 30 '18 at 6:40











  • Awesome @sid8491. Is there perhaps some documentation for this? Thanks.

    – JAWS007
    Dec 31 '18 at 4:55













  • @JAWS007 here you go

    – sid8491
    Jan 2 at 6:39
















1












1








1







In the fulfillment, if condition is false, just reply with the same question like Sorry this username does not exist, please enter the username again.



if not username:
res = json.dumps({
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


If you have some input context for the intent as well, then you need to set he context from the fulfillment as well.



req = request.get_json()
if not username:
res = json.dumps({
"outputContexts": [
{
"name": "{}/contexts/ask-username".format(req['session']),
"lifespanCount": 1,
},
],
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


EDIT:

To reset a parameter value, include the parameter in the output context as well in the webhook, and set #context.parameter as the default value of parameter in dialogflow console.
Documentation for setting default value of entity from context.



 "outputContexts": [
{
"name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/ask-username",
"lifespanCount": 1,
"parameters": {
"foo": ""
}
}
]


default value



Hope it helps.






share|improve this answer















In the fulfillment, if condition is false, just reply with the same question like Sorry this username does not exist, please enter the username again.



if not username:
res = json.dumps({
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


If you have some input context for the intent as well, then you need to set he context from the fulfillment as well.



req = request.get_json()
if not username:
res = json.dumps({
"outputContexts": [
{
"name": "{}/contexts/ask-username".format(req['session']),
"lifespanCount": 1,
},
],
"fulfillmentText": "Sorry this username does not exist, please enter the username again."
})


EDIT:

To reset a parameter value, include the parameter in the output context as well in the webhook, and set #context.parameter as the default value of parameter in dialogflow console.
Documentation for setting default value of entity from context.



 "outputContexts": [
{
"name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/ask-username",
"lifespanCount": 1,
"parameters": {
"foo": ""
}
}
]


default value



Hope it helps.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 6:51

























answered Dec 29 '18 at 6:57









sid8491sid8491

2,76431332




2,76431332













  • Thanks @sid8491 Is there a way to "go back"/clear a slot and get the next response from the user if the condition is not yet met? Similar to Rasa NLU's UserUtteranceReverted()?

    – JAWS007
    Dec 29 '18 at 23:12













  • @JAWS007 yes, you can include the slot in the output context and set their value to NULL, in the intent set default value of slot to #context.slot

    – sid8491
    Dec 30 '18 at 6:40











  • Awesome @sid8491. Is there perhaps some documentation for this? Thanks.

    – JAWS007
    Dec 31 '18 at 4:55













  • @JAWS007 here you go

    – sid8491
    Jan 2 at 6:39





















  • Thanks @sid8491 Is there a way to "go back"/clear a slot and get the next response from the user if the condition is not yet met? Similar to Rasa NLU's UserUtteranceReverted()?

    – JAWS007
    Dec 29 '18 at 23:12













  • @JAWS007 yes, you can include the slot in the output context and set their value to NULL, in the intent set default value of slot to #context.slot

    – sid8491
    Dec 30 '18 at 6:40











  • Awesome @sid8491. Is there perhaps some documentation for this? Thanks.

    – JAWS007
    Dec 31 '18 at 4:55













  • @JAWS007 here you go

    – sid8491
    Jan 2 at 6:39



















Thanks @sid8491 Is there a way to "go back"/clear a slot and get the next response from the user if the condition is not yet met? Similar to Rasa NLU's UserUtteranceReverted()?

– JAWS007
Dec 29 '18 at 23:12







Thanks @sid8491 Is there a way to "go back"/clear a slot and get the next response from the user if the condition is not yet met? Similar to Rasa NLU's UserUtteranceReverted()?

– JAWS007
Dec 29 '18 at 23:12















@JAWS007 yes, you can include the slot in the output context and set their value to NULL, in the intent set default value of slot to #context.slot

– sid8491
Dec 30 '18 at 6:40





@JAWS007 yes, you can include the slot in the output context and set their value to NULL, in the intent set default value of slot to #context.slot

– sid8491
Dec 30 '18 at 6:40













Awesome @sid8491. Is there perhaps some documentation for this? Thanks.

– JAWS007
Dec 31 '18 at 4:55







Awesome @sid8491. Is there perhaps some documentation for this? Thanks.

– JAWS007
Dec 31 '18 at 4:55















@JAWS007 here you go

– sid8491
Jan 2 at 6:39







@JAWS007 here you go

– sid8491
Jan 2 at 6:39




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53966323%2frepeating-dialogflow-intent-until-condition-is-met%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas