I was unable to find any documented way to accomplish to send email through GMAIL API, using url (GET request), something like this:
https://example_api/?action=send&to=someone#gmail.com&message=hello&auth_user=myuser#gmail.com&pass=xyz-app-pass
any ideas or tricks to accomplish that ? (so, I could use plain or app password).
I believe your goal as follows.
You want to send an email by accessing to the URL like https://example_api/?action=send&to=someone#gmail.com&message=hello&auth_user=myuser#gmail.com&pass=xyz-app-pass using Gmail API.
I thought that your goal can be achieved using Web Apps created by Google Apps Script. In this case, the script might be a simple. So in this answer, I would like to propose to achieve your goal using Web Apps created by Google Apps Script.
Usage:
Please do the following flow.
1. Create new project of Google Apps Script.
Sample script of Web Apps is a Google Apps Script. So please create a project of Google Apps Script.
If you want to directly create it, please access to https://script.new/. In this case, if you are not logged in Google, the log in screen is opened. So please log in to Google. By this, the script editor of Google Apps Script is opened.
2. Prepare script.
Please copy and paste the following script (Google Apps Script) to the script editor. This script is for the Web Apps.
function doGet(e) {
const allowedUsers = [
{email: "myuser#gmail.com", password: "xyz-app-pass"},
,
,
,
]; // If you want to allow other users to use this script, please add other emails and passwords to the `allowedUsers` array;
const subject = "sample subject";
const {action, to, message, auth_user, pass} = e.parameter;
if (action == "send" && allowedUsers.some(({email, password}) => email == auth_user && password == pass)) {
MailApp.sendEmail({to: to, subject: subject, body: message});
return HtmlService.createHtmlOutput("Email was sent.");
}
return HtmlService.createHtmlOutput("Email was not sent.");
}
3. Deploy Web Apps.
On the script editor, Open a dialog box by "Publish" -> "Deploy as web app".
Select "User accessing the web app" for "Execute the app as:".
By this, the script is run as the user which accessed to the Web Apps.
Select "Anyone" for "Who has access to the app:".
In this case, please access to the Web Apps using the browser. By this, when you login to the Google, the Web Apps can be used.
And, in this settings, when "User A" is access to the Web Apps by logging in Google, "User A" can also send the email using own Gmail. In this case, please add {email: "###", password: "###"} of "User A" to allowedUsers in the script. By this, only registered users can send the email.
If you don't want to share with other users, please set Execute the app as: Me and Who has access to the app: Only myself.
Click "Deploy" button as new "Project version".
Automatically open a dialog box of "Authorization required".
Click "Review Permissions".
Select own account.
Click "Advanced" at "This app isn't verified".
Click "Go to ### project name ###(unsafe)"
Click "Allow" button.
Click "OK".
Copy the URL of Web Apps. It's like https://script.google.com/macros/s/###/exec.
When you modified the Google Apps Script, please redeploy as new version. By this, the modified script is reflected to Web Apps. Please be careful this.
4. Testing Web Apps.
Please access to the URL of your Web Apps using your browser by including the query parameters as follows. When you have already been logged in Google, the script of Web Apps is run.
https://script.google.com/macros/s/###/exec?action=send&to=someone#gmail.com&message=hello&auth_user=myuser#gmail.com&pass=xyz-app-pass
Result:
When above script is run and auth_user and pass are included in allowedUsers, Email was sent. is returned.
Note:
When you modified the script of Web Apps, please redeploy the Web Apps as new version. By this, the latest script is reflected to Web Apps. Please be careful this.
If you want to access to the Web Apps using a script and curl, it is required to access to it using the access token. In this case, include the scope of https://www.googleapis.com/auth/drive.file (in some cases,might work /drive or /drive.readonly)
The Google Apps Script is a simple sample script for explaining the method for achieving your goal. So please modify it for your actual situation.
References:
Web Apps
Taking advantage of Web Apps with Google Apps Script
Related
targetwebsite.com has a google login button that takes you to the website:
https://targetwebsite.com/login/google
As a response you get the location:
https://accounts.google.com/o/oauth2/auth?client_id=867328024096-e1p5hbmra2s0g2psgqhhl7ldafla8qr9.apps.googleusercontent.com&redirect_uri=https://targetwebsite.com/login/google&response_type=code&scope=https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile&state=cH-mI0
Parts:
https://accounts.google.com/o/oauth2/auth
?client_id=867328024096-e1p5hbmra2s0g2psgqhhl7ldafla8qr9.apps.googleusercontent.com
&redirect_uri=https://targetwebsite.com/login/google
&response_type=code
&scope=https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile
&state=cH-mI0
If you log in there with google you come back to link
https://targetwebsite.com/login/google?state=cH-mI0&code=4/0AX4XfWjOprw2J7PfNFkaOCWLEAAiGDkm7UJQPmnzLRwnfp4IhhHf37XoyNsvr3DCGzmRcA&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20openid%20https://www.googleapis.com/auth/userinfo.email&authuser=1&prompt=none
The part "code=4/0AX4X..." is different for each login.
How would it be possible to automate this process? (in Powershell)
As far as I understand, Google only allows you to create permanent login tokens for your own projects, not for others as in this case.
I have created an agent in DialogFlow that interacts with the user giving her the ability to check for details like demographic from a back-end database. I have achieved this using Fulfillment/Webhook calls and have successfully parsed/returned different types of Responses to the user to play with. I have tested this on both an Android device and the Google Actions Simulator.
Now, what I want to achieve is to give user the ability to "Set a Reminder" on a platform like Google Calendar or similar through my App. By default, Google Assistant does this by simply telling it to "remind me..." and Google creates a reminder in the calendar. But as soon as I invoke my app, the Assistant is out of scope so using the "remind me" command won't work. I want to use the Google Calendar for example to create a reminder through my agent so that the user is notified at the due time.
I understand that when the user invokes an App in Google Assistant, she is using her Google credentials so I guess if I want to use the App to create a reminder, I should have the option. I have had a look at the Calendar API but I am not sure if I should proceed that way. Is there a better way of achieving this?
Please note, I want to use a reminder service that is available to the user without subscribing to a third-party service.
The Calendar API is the way to go. Details here.
In those docs you'll see reference to the access token, which you can get by using the helper intent askForSignIn (example of use here in one of Google's example projects).
Hope this helps!
So for all those who are facing the same issue, here is what I did:
First created an account on https://auth0.com
Followed this guide to configure the necessary settings to link to Google Assistant (ignored the Jovo part)
Used Auth0 guide to configure and link to my Google project credentials (ignored the Admins SDK Service part)
Now when I run my Google Actions App on the device, a button "Link [App Name] to Google" showed up. Clicking on that "signed me in".
Parsed the response in my webhook to grab originalRequest.data.user.accessToken
This is the token mentioned in #lukedavis answer. The next step was to use the token to execute a call to the Calendar API. Upon trying that, I am facing a different problem which I am trying to find the solution for. But the above should assist those who wish get the accessToken.
I can already connect my conversation to my Facebook page and the bot is working.
My Problem is that i couldn't find a single tutorial on how to make calls to a server that is owned by a company and has information about accounts and payments, for example when i type to the Chat-bot that i want to see a list of accounts, the chat-bot would reply with a list from that API; Or i can login to that server with my account by typing the account's name and password in the chat-bot. I just wanted to know if anyone knows how to do that or if its even possible or knows a tutorial that explains it. I also would prefer if the tutorial was detailed because i'm new to this field.
As #Felipe Paixao said, you need to develop an orchestrating application.
I've found one example that explains step-by-step how to use Watson Conversation with Facebook Messenger.
Requirements:
Facebook page
IBM Bluemix
A Facebook Developer Account
Source code.
Step - IBM Bluemix:
Create a SDK for Node.js application
Create a Watson Conversation service
Create your Workspace for Watson Conversation and build your Dialog
Configure the JS app and integrate it with the Watson Service Connections -> Connect Existent:
In your App created in IBM Bluemix, access the Tools and go to IDE Eclipse, and create a new file: app.js with this code.
Replace with your credentials the username and password
You can see your credentials inside Service Credentials, or going to your workspace and access:
Step - Facebook Developers:
Enter to facebook developers with your Facebook account
In the Dashboard select Create a New App and Select Messenger
Put the URL from your Bluemix (Now IBM Cloud) app and select the options marked: messages, message_deliveries, messaging_options e messaging_postbacks.
Now, return to our app to configure the app.js file with our new FB token autogenerated and deploy it.
Step Final
Test your chatbot: If you made everything OK, we will have your chatbot available on your Facebook page.
Obs.: For built your example, you can add the lines of code for call your API in the app.js using the http module, using the Advanced JSON in Watson Conversation and create one "action": "callApi", and recognize with your code for do something, like this example.
See the Official Reference that I used to build Facebook Messenger with Node.js SDK (Back-end) source code based on Priscila Parodi codes.
You need to develop an orchestrating application, that would be responsible to connect the IBM Watson Conversation with your desired Fronted, Facebook in this case, and the Backend systems. I imagine that you are using the automatic deploy to Facebook from the Conversation Tooling, this option would not resolve your need to access a Backend.
The image passed by #data_henrik shows exactly that.
In conversation, you can create context variables that will be used as triggers in the Orchestrator to let him know when you need to call a Backend service to provide an information and then write the response into the Conversation context.
About using the Chatbot to login into a system, passing a password, this isn't a safe option since all information typed would go to Watson Conversation log and any person with access to the tooling/api could see the passwords.
I've written an authorization flow for my action, to do account linking with the "Implicit flow". I have been testing it using the web simulator. When I try to run the action in the web simulator it tells me to link my account, and provides a URL:
"https://assistant.google.com/services/auth/handoffs/auth/start?provider=hello_dev&return_url=https://www.google.com/"
I run that URL and this is what happens:
My Java servlet receives the auth request from google. It contains what is documented, a GOOGLE_CLIENT_ID, a REDIRECT_URI, a STATE and "response_type=token"
I create an access-token from the Google ID that is logged in by using UserServiceFactory.getUserService().getCurrentUser().getUserId()
I craft a URL to the redirect-uri that contains my ACCESS_TOKEN, token_type=bearer, and state= the state string I originally received
I create a web page for the user that contains that link so they can click it and it executes the link and my account is linked.
That works great and the response is a blank page with a URL that says: "https://www.google.com/?result_code=SUCCESS&result_message=Accounts+now+linked."
However, I wanted a flow that allowed the user to ensure they are logged in, and logged into the Google Account they wanted to link
So, I also present a link that logs them out if they'd like. The link is created by using userService.createLogoutURL(thisUrl)
If they do that, I then present them a link to log in, created using userService.createLoginURL(thisUrl)
Once they have logged in, with a different Google ID, they are back on the original page which allows them to log out again or click the "link account" link.
The situation is, that if they click the "link account" link now, the EXACT same link that would have worked successfully before they logged out (except a different ACCESS_TOKEN value) and logged back in with a different account, the response is a blank page with a URL that says: "https://www.google.com/?result_code=FAILURE&result_message=Account+linking+failed"
Two things of note:
If they log out and log back in with the same account, then the "link account" URL works fine
If they are not logged in at all when beginning the process, and then log in and then use the "link account" link it works fine
So, the only time it fails is when they are logged in, log out, log in with a different account, and click to link accounts. That's when it fails.
The account doesn't matter, multiple different accounts work, as long as the browser is logged into the first account and doesn't change during the flow.
I honestly cannot imagine how this is happening.
This gets even worse if I do it in the Google Home app, as it then returns some "malformed request error" page and basically stops working, PERMANENTLY. Stopping/Starting the action didn't help. Stopping/Starting the Web service didn't help. Rebooting the Android device didn't help. Link Account from the Google Home app was permanently broken. The only way I was able to get it working again was to use the Account Link URL (gotten from the web simulator) in the Chrome Browser on my Android device, which seemed to "reset" everything.
At this time, we require that the Google user who initiates the account linking process, both via the simulator and Google Home application, be the same Google user that logs in via a Google Sign-in option, if it is offered as part of your auth flow. This is a hard requirement.
For this reason, we'd suggest not offering a Google logout option as part of your account linking process.
Our team is building an app that has Facebook login requirement (in addition to other oauth/identity providers such as LinkedIn, Google, end so on).
The app is obviously in the sandbox mode, so in order to develop/play with it, it requires developer accounts for each team member, otherwise login flow just fails.
My problem is that, as an app "owner" I don't see a way how to register developers or testers that are not in my friend list. I tried to put an e-mail address of one of my colleagues that she is using for facebook account, but Facebook did not accept it with the message that user id could not be resolved. And I really do not want "to friend" with anyone. Making the app live is not an option either as it required review process, and we are pretty far from finishing this.
So is there any solution?
Update: Here is the error message shown to the user when she is not registered as a developer:
App Not Setup: The developers of this app have not set up this app
properly for Facebook Login.
Ok, figured it out. An app owner can use an alias that comes with the "facebook email" (whatever is in front of #facebook.com)
To access this special id, you need to go through the set of links:
Your profile page
Then click About
Then click "Contact and Basic info"
Then click on emails link to show your emails (emails hidden from Timeline)
Then find #facebook.com email and take the part before the # and use it
for registering