How to show textInput and keyboard programmatically - expo

I'm in charge to a build a react-native chatbot app, that must help users to signup during the discussion.
The chat must start with a greeting message and few quick-replies, in which we find a "Sign me up" option. When the user presses that option, the bot asks hem to write an email address in order to start the process.
I've made a little project based on the example available on react-native-gifted-chat repository.
Please use this link to get to my code: https://github.com/firas1220/react-native-chatbot
I'd appreciate if someone gives some hand or maybe we can add improvements and transform the repo into something original 😉.
This question might help some people facing similar situations.
As an attachment, a demo in GIF image.

Just add an InputText (https://reactnative.dev/docs/textinput) and then to ref.current.focus()
Something like this:
const inputRef = useRef();
const onAction = () => {
inputRef.current.focus();
}
<InputText ref={inputRef} value=... />

Related

I don't understand how my google action shows up on "Works with Google" search

I have followed below tutorial to build my own home action.
https://github.com/actions-on-google/smart-home-nodejs
I don't understand well on how this works. Let me explain you all about what I have understood so far and what I have done by now.
What I have DONE :
I built a conversational action (built with dialogflow's inline editor and intents) to change a data of the Firebase realtime database. (for instance, when I say "Turn the light on", then the Firebase data 'LED/OnOff' turns 0 to 1). Below is the code I have in my Dialogflow inline editor. (I have excluded the field including my project's credentials.)
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
admin.initializeApp();
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function handle_heatOn(agent) {
const state = agent.parameters.heat_on;
console.log(state);
var heat = 0;
if (state == 1)
heat = 1;
return admin.database().ref('0/OnOff').update({
on : true
});
}
function handle_heatOff(agent) {
const state = agent.parameters.heat_on;
var heat = 0;
if (state == 0)
heat = 0;
return admin.database().ref('0/OnOff').update({
on : false
});
}
//some more functions, related to controlling 4 different devices (heater, cooler, exhaust fan, LED) - exempted
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('heat_on', handle_heatOn);
intentMap.set('heat_off', handle_heatOff);
intentMap.set('cool_on', handle_coolOn);
intentMap.set('cool_off', handle_coolOff);
intentMap.set('exha_on', handle_exhaOn);
intentMap.set('exha_off', handle_exhaOff);
intentMap.set('led_on', handle_ledOn);
intentMap.set('led_off', handle_ledOff);
// intentMap.set('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
Then I have deployed my action and Google has approved my action! It is now in production and can be searched in anyone's google account.
I have set up an OAuth 2.0 server. I'm really a beginner in developing, so I managed to use Auth0 to make the server. I have followed the below tutorial :
https://v3.jovo.tech/tutorials/google-action-account-linking-auth0
As a conclusion, when I invoke my conversational action in anyone's Google Assistant App, It will prompt the user to the authentication (login) screen (By Auth0). After the user inputs ID and Password, google assistant will link the user's account and launch my app.
However, my action is not shown on Google Home's "Works with Google" category. After trying to complete Brand Verification in Google Actions Console and linking one of my existent app on Google Play, I still don't know what to do or where to start from.
What I have understood so far :
Sorry for my shallow understanding in advance. I have understood that once my action is invoked by a user, it has to do account linking, which requires OAuth 2.0 server to exchange authentication token. If exchanging token has succeeded, the user's account is linked and he/she is able to use my action. The action will be launched after that.
I have searched the Internet and found some information such as Deep Linking and App Discovery, but I'm not sure this is the right keyword to start from.
I know I am really lacking in knowledge here. Please kindly at least hint where I should study and start.
What I want to understand and do :
I want to make my action, which is in production, show up on Google Home and Google Assistant App's "Works With Google" category without the prefix [test]. In other words, I want to let my app be searched just as the other company's apps. I understand that if you click on one of the apps of a company, your account will be linked and the company's action would be launched. Maybe I have to add some lines on Dialogflow's inline editor?? I know I might be silly, but I really appreciate your help. Thank you for reading my post.

AWS QnA Bot Solution change the Alexa welcome message

I have an AWS QnA Bot that I am using with Alexa. The default welcome message for Alexa with this solution is:
"Hello, Please ask a question".
I'd like to change this to make it more personalized for my bot but I'm not sure where to make this change in the Lambda code.
I went into the Lambda function that the built-in tutorial told me to use for the Alexa Skill endpoint. Here, I found a section called get_welcome_message that looks like this:
async function get_welcome_message(req, locale){
console.log("=================" + JSON.stringify(req));
const welcome_message = _.get(req,'_settings.DEFAULT_ALEXA_LAUNCH_MESSAGE', 'Hello, Please ask a question');
if (_.get(req._settings, 'ENABLE_MULTI_LANGUAGE_SUPPORT')){
return await translate.get_translation(welcome_message,'en',locale,req)
} else {
return welcome_message;
}
}
I thought that changing the welcome_message would change it in the Alexa skill. However, no matter what I change it to, it will still say: "Hello, Please ask a question".
I've tried clearing my history/cache in case that was an issue. I've deployed the altered Lambda, rebuilt the AWS QnA Bot, and rebuilt the Alexa Skill. I've also looked through the Lambda and this function seems to be the only place where a welcome message is set. It looks like everything that requires the welcome message calls this middleware.
This seems like it should be a simple task to change but I just can't seem to get it to show a different welcome message.
Please let me know how I can change this default welcome message. I feel like it's something simple that I'm missing.
An easier approach would be to change the value of DEFAULT_ALEXA_LAUNCH_MESSAGE from Content Designer UI. This doesn't require any code changes.
You can find the instructions to access content designer here. Here is how you can change the settings.

AWS Amplify federated google login work properly on browser but dont work on Android

The issues are when I am trying to run federated authentication with the help of amplify auth method on the browser it works fine, but when I try to run it on my mobile.
It throws error No user found when I try to use Auth.currentSession() but the same work on the browser.
tried to search about this type of issue but I found related to ionic-cordova-google-plugin not related to AWS Amplify Federated Login Issue.
Updating the question after closing the question with less debugging information without asking for any information.
This is issues raised in git hub with respect to my problem.
Issue No. 5351 amplify js it's still in open state.
https://github.com/aws-amplify/amplify-js/issues/5351
Another issue 3537 which is still in Open
These two issues has the same scenario like me, I hope its enough debugging information, if more required mention comment instead of closing without notification, it's bullying for a beginner not helping
I fixed the above problem by referring a comment or wrapped around fix.
Link that will take to that comment directly link to comment.
First read the above comment as it will give you overall idea of what exactly the issue is instead of directly jumping to the solution.
Once you read the comment you will be little unclear with respect to implementation as he has use capacitor and not every one are using capacitor.
In my implementation I ignore this part as I am not using capacitor.
App.addListener('appUrlOpen')
Now lets go to main step where we are fixing this issue, I am using deep links to redirect to my application
this.platform.ready().then(() => {
this.deeplinks
.route({
"/success.html": "success",
"/logout.html": "logout",
})
.subscribe(
(match: any) => {
const fragment = JSON.stringify(match).split('"fragment":"')[1];
// this link can be your any link based on your requirement,
// what I am doing it I am passing all the data which I get in my fragments.
// fragments consists of id_token, stage, code,response type.
// These need to be passed to Ionic in order for Amplify to run its magic.
document.location.href = `http://192.168.1.162:8100/#${fragment}`;
},
(nomatch) => {
console.log("Got a deeplink that didn't match", nomatch);
}
);
});
I got this idea by referring the issue in which the developer mentioned of sending code and state along with application deep linking URL.

Selenium webdriver - Python won't click a button on a website

This is my first question on Stack Overflow. I am not much of a programmer, I just learnt about Selenium and went as far as I could but there is this mistake I can't fix alone so I am asking for help. I am using Python 2.7 in PyCharm.
As of now, I have been using anything.send_keys(Keys.ENTER) to click some buttons in my code as the .click() function always returned me a ElementNotInteractableException error in Chrome for this website. The goal here is simply to clear a text area, insert the list of genes down there and click on this "submit" button. This is supposed to show me an updated table that I want to download.
For this one troublesome button though, nothing works. The thing is, it doesn't even return an error, the code keeps going on as if it indeed had clicked, and it eventually downloads the non-updated table. I tried switching to Firefox, where neither .click() nor .send_keys(Keys.ENTER) worked (I never get an error as well, it just downloads the wrong table). Clicking myself does work and produces the updated table.
Based on other questions I saw here, I tried using ActionChains or scroll_into_view but still, nothing happens. Here is the code :
baseline_url = "http://mtsspdb.noble.org/atlas-internal/3880/transcript/profile/5?charttype=barchart&sessionid=1553076490500118&feature_accs=%20Medtr1g079760.1"
driver = webdriver.Chrome("C:\Webdrivers\chromedriver.exe")
driver.set_page_load_timeout(30)
driver.get(baseline_url)
driver.maximize_window()
peptides_list = """Medtr4g068220.1
Medtr1g107390.1
Medtr1g018740.1
Medtr5g016470.1
Medtr4g095002.1
Medtr5g004930.1
MT4Noble_020581.1
Medtr1g107395.1
Medtr1g107400.1
Medtr1g107405.1
Medtr1g107410.1
Medtr4g095010.1
MT4Noble_057127.1
"""
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, "//*[#id='feature_accs']")))
text_area = driver.find_element_by_xpath("//*[#id='feature_accs']")
text_area.clear()
text_area.send_keys(peptides_list)
time.sleep(1)
troublesome = driver.find_element_by_xpath("//*[#id='form1']/div[8]/div/input")
print troublesome
#scroll_into_view = troublesome.location_once_scrolled_into_view
ActionChains(driver).move_to_element(troublesome).send_keys(Keys.ENTER)
time.sleep(3)
print "Sucess for x"
The html location of this button is
<input class="btn btn-primary" type="submit" name="submit" value="Submit">
Do you have any idea on how to click it, and most of all on why it doesn't work ?
Many thanks
PS: As I said previously, it is my first question. Please tell me if I need to update/change something.
This will definitely work, as I just tried it given your information
driver.execute_script("$('#form1').find('.btn-primary').click()")
Now, there must be something strange about it finding the element, as Selenium would error if it could not click. So the element we are clicking with the code must not have the events we expect it to have. I am investigating more and will update this with specifics.
Edit:
Interesting. The submit button does not seem to have normal event listeners.
getEventListeners($(".btn-primary")[0]);
$._data($(".btn-primary")[0], "events");
Both of these return nothing. This would seem to be the cause of the Selenium issue. It isn't triggering the actual submission with its click. Selenium does not use Javascript, and also does not use a real user32.dll (Windows ex) click, so it does not always behave identically to a real click or a javascript click.
Welcome to SO. Here is the option to click on the button.
Option 1: click using javascript
driver.exeucte_script("arguments[0].click();",troublesome)
Option 2: Scrolling to element
troublesome.location_once_scrolled_into_view
troublesome.click()
This works well for me:
for i in range(1, 10):
try:
driver.find_element_by_xpath(
f'/html/body/div[{i}]/div/div[2]/span[1]/span/span/input').click()
except:
pass

Pywinauto 0.6.0 access browser URL in edit control for Firefox

I am currently trying to access URL of the active window for Firebox browser using Pywinauto 0.6.0, as part of a python app that can track website usage. I am a newbie python programmer, so if I have made some obvious mistakes then this is why.
I have read all the material I can find on Google and the Pywinauto docs, but there are no clear indications of how to do this, atleast not without using "Typekeys" after connecting to a window.
In fact, I have been able to access to the URL the "hack" way by connecting to the browser window with pywinauto, then using "TypeKeys()" to grab the URL and copy it to clipboard. But this approach will not work for me, as it interrupts the user and my app must run in the background whilst the user is accessing their system as usual. Using the typekeys method introduces some odd mouse and window behaviour when changing or refreshing windows and then trying to grab the URL - so the approach has proven unworkable for me.
Currently the code I have is as follows (I have used the window text title='' of a specific window I am using for testing, in practice it is whichever the active tab on the browser is):
from pywinauto import *
app = application.Application()
app.connect(title=u'Facebook - Log In or Sign Up - Mozilla Firefox', found_index=0)
window = app.top_window_()
window.PrintControlIdentifiers()
titlebar = window.child_window(title=u'Facebook - Log In or Sign Up - Mozilla Firefox')
toolbar = titlebar.child_window(title=u'Navigation Toolbar')
combobox = toolbar.child_window(title=u'Search or enter address')
edit = combobox.child_window(title=u'Search or enter address')
I use PrintControlIdentifiers() in order to see which elements I can interact with, but this returns only
MozillaWindowClass - 'Facebook - Log In or Sign Up - Mozilla Firefox' (L-32000, T-32000, R-31840, B-31944)
[u'Facebook - Log In or Sign Up - Mozilla Firefox', u'MozillaWindowClass', u'Facebook - Log In or Sign Up - Mozilla FirefoxMozillaWindowClass']
I can access the Firefox Window fine with the current active tab, but next when trying to access the ChildWindow and subsequent ChildWindow there is no error, until I try and do something with the childwindow e.g., Click() function on what I think in the URL bar UI element. However, I am not sure even if the code is even accessing the child window element correctly in the first place. Or if this the right way to try and filter through the child elements to get to the URL edit control element.
As can be seen in the below image of the tree view of the UI elements (using UISPY.exe), the following tree to access the firefox browser edit control element that contains the URL is:
Tree view of Firefox UI elements via UISPY
"window" -> "title bar" -> "tool bar" "Navigation Toolbar" -> "combo box" -> "Search or enter address" -> "edit" "Search or enter address
where the "edit" control contains the attribute Value, Value:"url", which I need to extract to a variable.
Any help with this would greatly appreciated.
This is probably too late to post but incase any future developers has similiar question. Here is working solution.
Just pass backend='uia' as argument like application.Application(backend='uia'). Now, accessing and performing actions on child_window is possible.
Here is complete code snippet for any url.
url='https://google.com'
app = application.Application(backend='uia').connect(title_re=".*Mozilla Firefox")
main_firefox_winspec = app.window(title_re=".*Mozilla Firefox")
address_bar = main_firefox_winspec.child_window(title_re=".*or enter address", control_type="Edit")
address_bar.set_edit_text(url)
time.sleep(3)
main_firefox_winspec.child_window(title="Go to the address in the Location Bar").wrapper_object().click_input()