On https://mail.google.com/mail/u/0/#settings/accounts there is an option to Check email for other accounts. Normally Gmail checks those accounts for new mail every 60 minutes. With the 'Check mail now' button you can manually trigger this.
Does anyone know if this button can be triggered via a url / shortcut / api? I would like to create a button/script for myself to push when I want to check for new mail.
I solve it from this link:
tutorial link
Now I have an Bookmarklet with a javascript command that does automatically the 4 clicks to reach the "Check Email Now".
Hope that it help you too.
This is the code in javascript:
(function () { const gmailWindow = window;
if(gmailWindow.location.href.indexOf("https://mail.google.com/") === -1){
alert('É preciso estar no Gmail para utilizar este recurso.');
return;
}
gmailWindow.location.assign('https://mail.google.com/mail/u/0/#settings/accounts');
const xpath = "//span[text()='Ver correio agora']";
const refreshAccounts = () => { const selectedNodeElements = gmailWindow.document.evaluate(xpath, gmailWindow.document, null, XPathResult.ANY_TYPE, null);
let currentNode = selectedNodeElements.iterateNext();
if (currentNode === null) {
setTimeout(refreshAccounts, 100);
} else {
while (currentNode) { currentNode.click(); currentNode = selectedNodeElements.iterateNext();
};
gmailWindow.location.assign('https://mail.google.com/mail/u/0/#inbox'); }; };
setTimeout(refreshAccounts, 100); })();
Related
I'm having difficulty figuring out what most likely is a simple issue, which relates to a 'if then else' problem in my code (NodeJS, Bot Framework v4).
I can't quite figure out why the relevant card isn't being shown depending on the number of semi-colons it finds in the response string from QnAMaker.
When testing with the Bot Framework emulator, it only returns one response type, whether that's plain text or one Rich Card no matter how many semi-colons are in the response.
I've tried to see if it's the length of the string it's having problems with by parsing the number value in the length statement. Didn't make a difference sadly. Notably if I use any other conditional operator such as '===' for example, it breaks the response completely.
const { ActivityTypes, CardFactory } = require('botbuilder');
const { WelcomeCard } = require('./dialogs/welcome');
// const { HeroCard } = require('./dialogs/welcome');
// const { VideoCard } = require('./dialogs/welcome');
class MyBot {
/**
*
* #param {TurnContext} on turn context object.
*/
constructor(qnaServices) {
this.qnaServices = qnaServices;
}
async onTurn(turnContext) {
if (turnContext.activity.type === ActivityTypes.Message) {
for (let i = 0; i < this.qnaServices.length; i++) {
// Perform a call to the QnA Maker service to retrieve matching Question and Answer pairs.
const qnaResults = await this.qnaServices[i].getAnswers(turnContext);
const qnaCard = qnaResults.includes(';');
// If an answer was received from QnA Maker, send the answer back to the user and exit.
if (qnaCard.toString().split(';').length < 3) {
await turnContext.sendActivity(qnaResults[0].answer);
await turnContext.sendActivity({
text: 'Hero Card',
attachments: [CardFactory.heroCard(HeroCard)]
});
} else if (qnaCard.toString().split(';').length > 3) {
await turnContext.sendActivity(qnaResults[0].answer);
await turnContext.sendActivity({
text: 'Video Card',
attachments: [CardFactory.videoCard(VideoCard)]
});
} else if (qnaCard.toString().split(';').length === 0) {
await turnContext.sendActivity(qnaResults[0].answer);
return;
}
}
// If no answers were returned from QnA Maker, reply with help.
await turnContext.sendActivity('No QnA Maker answers were found.');
} else {
await turnContext.sendActivity(`[${ turnContext.activity.type } event detected]`);
} if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
// Handle ConversationUpdate activity type, which is used to indicates new members add to
// the conversation.
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
// Do we have any new members added to the conversation?
if (turnContext.activity.membersAdded.length !== 0) {
// Iterate over all new members added to the conversation
for (var idx in turnContext.activity.membersAdded) {
// Greet anyone that was not the target (recipient) of this message
// the 'bot' is the recipient for events from the channel,
// context.activity.membersAdded == context.activity.recipient.Id indicates the
// bot was added to the conversation.
if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id) {
// Welcome user.
// When activity type is "conversationUpdate" and the member joining the conversation is the bot
// we will send our Welcome Adaptive Card. This will only be sent once, when the Bot joins conversation
// To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
await turnContext.sendActivity({ attachments: [welcomeCard] });
}
}
}
}
}
}
module.exports.MyBot = MyBot;
Ideally, what I'm hoping to see is if I ask a question which has 3 semi-colons in the response, it outputs a Hero Card. If it has more than 3, then a Video Card and if it doesn't have either, a text response.
I'm not a js specialist, but I'm quite confused by the following:
const qnaCard = qnaResults.includes(';');
In Javascript, includes is the following (source):
The includes() method determines whether an array includes a certain
value among its entries, returning true or false as appropriate.
So here your qnaCard is true or false. But it looks like you are trying to use it as if it was containing the text:
if (qnaCard.toString().split(';').length < 3) {
...
You have to work on the object containing the answer: qnaResults[0].answer.
What I need to do is make my bot after replying to something wait for user response so that he can reply with a flow ending messege Example:
User: clicks the Get Started button
Bot: I can help you with the following (Payment) (option2) (option3)
User: clicks Payment
Bot: Can you please enter the bill number
User:3922509234
.............................
Bot:Ok thank you, your payment will be processed
this is how the facebook app comunicates with the bot
app.post('/webhook', function(request, response) {
var data = request.body;
if(data.object == 'page'){
data.entry.forEach(function(pageEntry){
pageEntry.messaging.forEach(function (messagingEvent) {
if(messagingEvent.message){
console.log("MESSAGE---------------------> ",messagingEvent);
var messageInfo = functions.reciveMessage(messagingEvent);
console.log("MESSAGEINFO ", messageInfo);
evaluateMessage(messageInfo);
}
if(messagingEvent.postback){
console.log("POSTBACK--------------------> ",messagingEvent);
var postBackInfo = functions.recivePostBack(messagingEvent);
evaluatePostBack(postBackInfo);
}
});
});
response.sendStatus(200);
}
});
This is where the user's input is evaluated for keywords
function evaluateMessage(messageInfo, type) {
if(functions.isWordContain(messageInfo.senderMessage,'Pagar')||
functions.isWordContain(messageInfo.senderMessage,'pagar')||
functions.isWordContain(messageInfo.senderMessage,'Factura')||
functions.isWordContain(messageInfo.senderMessage,'factura')){
var message = functions.sendTextMessage(messageInfo.senderId, "Por
favor ingresa el numero de tu contrato");
callSendAPI(message);
}
}
The messageInfo is check if contains the keyWord then returns the message to the user.
How do i make the bot wait for user input so that he can reply
Im using Node.Js with express not any bot building platform please help
I found an easy way of doing this though there might be a better way a made a global variable
var verifier = {
origin:null,
state:false
};
then when it enters the message validator and modifies the json with a sort of token and sets the state to true
function evaluateMessage(messageInfo) {
if (functions.isWordContain(messageInfo.senderMessage,'Pagar')||
functions.isWordContain(messageInfo.senderMessage,'pagar')||
functions.isWordContain(messageInfo.senderMessage,'Factura')||
functions.isWordContain(messageInfo.senderMessage,'factura')){
var message = functions.sendTextMessage(messageInfo.senderId, "Por favor
ingresa el numero de tu contrato");
verifier.origin = 'pagoFactura';
verifier.state = true;
callSendAPI(message);
}
}
later where the messages enter I just ask if that state is true and which is the origin and depending if its one or the other I send a message
app.post('/webhook', function(request, response) {
var data = request.body;
if(data.object == 'page'){
data.entry.forEach(function(pageEntry){
pageEntry.messaging.forEach(function (messagingEvent) {
if(messagingEvent.message){
if(verifier.state == false){
console.log("MESSAGE---------------------> ",messagingEvent);
var messageInfo = functions.reciveMessage(messagingEvent);
console.log("MESSAGEINFO ", messageInfo);
evaluateMessage(messageInfo);
}else {
console.log("verifierOrigin ", verifier.origin);
var messageInfo = functions.reciveMessage(messagingEvent);
switch (verifier.origin) {
case 'pagoFactura':
var message = functions.sendTextMessage(messageInfo.senderId,
"Gracias su pago se a procesado exitosamente");
callSendAPI(message);
break;
default:
}
}
}
if(messagingEvent.postback){
console.log("POSTBACK--------------------> ",messagingEvent);
var postBackInfo = functions.recivePostBack(messagingEvent);
evaluatePostBack(postBackInfo);
}
});
});
response.sendStatus(200);
}
});
If someone finds a better way please comment also I know this is not the best way this is just for testing purposes
How to add image of the bot with some welcome text in the middle in Microsoft Bot Framework Web Chat. Seems like quite common functionality and I see images which indicates that is possible.
Anyone knows how to add it?
you can use the below code and replace your image path to give response from bot to user including text and image.
await context.PostAsync("Here we go with the welcome message\n"+"![AN IMAGE!](Your_Image_URL)");
Another way is, you can also use Card functionality:
private async Task Greeting(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var message = await argument;
if (string.IsNullOrEmpty(message.Text))
{
// Hero Card
var cardMsg = context.MakeMessage();
var attachment = BotWelcomeCard("Hello,I am a bot.", "");
cardMsg.Attachments.Add(attachment);
await context.PostAsync(cardMsg);
}
else
{
// else code
}
}
private static Attachment BotWelcomeCard(string responseFromQNAMaker, string userQuery)
{
var heroCard = new HeroCard
{
Title = userQuery,
Subtitle = "",
Text = responseFromQNAMaker,
Images = new List<CardImage> { new CardImage("../img/bot.gif") },
Buttons = new List<CardAction> { new CardAction(ActionTypes.ImBack, "Show Menu", value: "Show Bot Menu") }
};
return heroCard.ToAttachment();
}
ok, here is what we end up doing:
<script>
$(document).ready(function () {
$(".wc-header").append("<div class='wc-header-welcome'><img src='/Images/bot.png'/><div>Hello! I am your bot</div>");
});
</script>
Hope it will help save time to someone else.
I'm trying to implement google login in my app using xamarin.auth like below
var auth = new OAuth2Authenticator("284202576320-7kgdhaa5sgvkoe03jmmcv0p8lfdma306.apps.googleusercontent.com","cAZW7uegD-h2-
tNMMf5q1UGQ","https://www.googleapis.com/auth/userinfo.email",new
Uri("https://accounts.google.com/o/oauth2/auth"),new
Uri("http://dev.myfav.restaurant/Account/LoginComplete"),new
Uri("https://accounts.google.com/o/oauth2/token"),null,true)
{
AllowCancel = true,
};
but Completed event not firing and its going to web page after login :(
I'm getting below error
i need to get back user to my app how can i achieve this ???? Can anyone help me on this please.
Thanks in advance
Hey follow these two examples one is using web view and one is using google sign in sdk for google auth.
https://timothelariviere.com/2017/09/01/authenticate-users-through-google-with-xamarin-auth/
and
https://developer.xamarin.com/samples/xamarin-forms/WebServices/OAuthNativeFlow/
So according to this issue reported by Mounika.Kola .I think u should refer that authenticator.Completed -= OnAuthCompleted is there in ur code. For reference just see these codes which i used for google authorization in Xamarin Forms.
void OnLoginClicked(object sender, EventArgs e)
{
string clientId = null;
string redirectUri = null;
switch (Device.RuntimePlatform)
{
case Device.iOS:
clientId = Constants.iOSClientId;
redirectUri = Constants.iOSRedirectUrl;
break;
case Device.Android:
clientId = Constants.AndroidClientId;
redirectUri = Constants.AndroidRedirectUrl;
break;
}
var authenticator = new OAuth2Authenticator(
clientId,
null,
Constants.Scope,
new Uri(Constants.AuthorizeUrl),
new Uri(redirectUri),
new Uri(Constants.AccessTokenUrl),
null,
true);
authenticator.Completed += OnAuthCompleted;
authenticator.Error += OnAuthError;
AuthenticationState.Authenticator = authenticator;
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(authenticator);
}
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
{
var authenticator = sender as OAuth2Authenticator;
if (authenticator != null)
{
authenticator.Completed -= OnAuthCompleted;
authenticator.Error -= OnAuthError;
}
User user = null;
if (e.IsAuthenticated)
{
// If the user is authenticated, request their basic user data from Google
// UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo
var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
var response = await request.GetResponseAsync();
if (response != null)
{
// Deserialize the data and store it in the account store
// The users email address will be used to identify data in SimpleDB
string userJson = await response.GetResponseTextAsync();
user = JsonConvert.DeserializeObject<User>(userJson);
}
if (account != null)
{
store.Delete(account, Constants.AppName);
}
await store.SaveAsync(account = e.Account, Constants.AppName);
await DisplayAlert("Email address", user.Email, "OK");
}
}
I hope it helps you.
In iOS once you have completed the authentication with Xamarin.Auth you just need to dismiss the viewController and you will be put back in your app.
You do this subscribing to the Completed event of the OAuth2Authenticator
auth.Completed += (sender, e) =>
{
DismissViewController(true, null);
};
If the "Native UI" is used (the last parameter in the constructor is set to true), which means that external/system browser is used for login not WebView. So, on Android instead of WebView [Chrome] CustomTabs is used and on iOS instead of UIWebView (or WKWebView) SFSafariViewController is used.
With native UI user is leaving your app and the only way to return to your app is app-linking (or deep-linking) and this requires completely different approach.
1st you cannot use http[s] scheme for redirect_url (OK on Android it is possible, but on iOS not). Use custom scheme for that.
See the sample[s] (Xamarin.Forms ComicBook):
https://github.com/moljac/Xamarin.Auth.Samples.NugetReferences
And the docs in the repo:
https://github.com/xamarin/Xamarin.Auth/tree/master/docs
I'm trying to implement an inapp purchase for my Chrome Extension. I have followed the guide on https://developer.chrome.com/webstore/payments-iap, added 1 buyable item and implemented following code on an onclick event:
google.payments.inapp.getSkuDetails({
'parameters': {'env': 'prod'},
'success': onSkuDetails,
'failure': onSkuDetailsFail
});
var onSkuDetails = function (response) {
console.log("onSkuDetails", response);
/*var products = response.response.details.inAppProducts;
var count = products.length;
for (var i = 0; i < count; i++) {
var product = products[i];
addProductToUI(product);
}
getLicenses();*/
}
var onSkuDetailsFail = function(result){
console.log("onSkuDetailsFailed", result);
}
But every time I click it, I get
onSkuDetailsFailed > "INVALID_RESPONSE_ERROR"
I have added the buy.js and changed some permissions, but still don't see where the problem might be.
Do note, that I'm testing this extension locally and not from the Chrome webstore using my own account and a friend's account which I included as testperson on the dashboard.