I am trying to figure out if it is possible to trigger a python script to be run using google home? I would like to do something like saying "Hey Google run my python script." And from the Google home would execute running my python script. Anyone know if that is possible?
You could create a Dialogflow app that integrates with the Google Assistant so that when you invoke the app it sends a HTTP request to your server. You could setup your server so that it runs your Python script when you receive that HTTP request.
Tutorial to create a Dialogflow app: https://dialogflow.com/docs/getting-started/building-your-first-agent
I had to do this for my assistant as well. Here's what I did:
First I made a PHP script which wraps my Python script.
The code goes like this:
<?php
$resolved_query = $_POST['resolved_query'];
$keywords=shell_exec('/usr/bin/python <YOUR PYTHON FILE NAME>.py "'.$resolved_query.'"');
echo $keywords;
?>
Next I changed my Default Fallback Intent in dialogflow so that it uses webhook. You can see this option at the bottom of the page in Default Fallback Intent.
Now, in order for you to return the result from Python script, just print the result in your Python script. Like:
print result
Now, if your Python file executes successfully, the result will be stored in $keywords. Just print that out and your response will be back at dialogflow.
This is basically how you can get your Python script to be run by dialogflow.
Related
I can see the Service Account usage out of gcloud CLI by doing as such:
gcloud policy-intelligence query-activity --activity-type=serviceAccountKeyLastAuthentication --project=<project_name>
I would like to replicate this in a python script..
I am attempting to this do this but I am not sure how to authenticate, and I am getting a 401 error, despite having enabled the API. I am following this documentation. https://cloud.google.com/policy-intelligence/docs/activity-analyzer-service-account-authentication#iam-get-service-account-key-id-rest
import requests
r = requests.get(f"https://policyanalyzer.googleapis.com/v1/projects/{self.project_id}/locations/global/activityTypes/serviceAccountKeyLastAuthentication/activities:query?filter=activities.full_resource_name%3D%22%2F%2Fiam.googleapis.com%2Fprojects%2F{self.project_id}%2FserviceAccounts%2F{self.sa_email}%2Fkeys%2F{self.key_id}%22"
Is there some way I need to authenticate my request call? The rest of the script I am using the python client libraries using discovery.build and authenticating as such:
credentials, project = google.auth.default()
self.crm = discovery.build("cloudresourcemanager", "v3", credentials=credentials)
There does not seem to be a "policy analyzer" python library, so I am not sure on next steps.
The end goal is to see the last key authentication time of every service account key in the organization.
Thanks!
You may check this link for the sample Python code
Do note that the feature is still in preview and does not have a Python client for the same yet. The gcloud cli and REST is the way of accessing this feature programmatically.
Take a look at the python example shown towards the bottom of the page here:
https://cloud.google.com/iam/docs/reference/rest/v1/projects.serviceAccounts.keys/list
It shows how to get application default credentials used to pass in the client. You could accomplish the same with http requests, but that example above should help.
Also, looking at the original curl request, if you decode the filter to unicode it should be:
activities.full_resource_name="//iam.googleapis.com/projects/PROJECT_ID/serviceAccounts/SERVICE_ACCOUNT_EMAIL/keys/KEY_ID"
Assuming you got it from the sample [curl][1] request.
[1]: https://cloud.google.com/policy-intelligence/docs/activity-analyzer-service-account-authentication#view-recent-specific-key
I created a Telegram bot in Python (3.7) to retrieve articles from a website. I used the start_polling() method from the Python telegram bot library to get commands from the user, but when I run the file in my command line (Windows OS), there is no response at all. The file keeps running and doesn't terminate, and any messages sent to the bot aren't responded to either. The code snippet is given below.
YOUR_TOKEN = secret!
WELCOME = 'Welcome!'
def brain_pickings():
final_reply = pickings()
bot.sendMessage(text=final_reply,parse_mode='html')
updater = Updater(token=YOUR_TOKEN)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler('start', my_start))
dispatcher.add_handler(CommandHandler('brainpickings', brain_pickings))
updater.start_polling()
print('it is happening!')
updater.idle()
print('it is idle!')
The bot does not respond to /start or /brainpickings. The output on the command line (where I had entered the command to run the file):
C:\Users\ANJALI\.vscode\telegbot>python main.py
it is happening!
PS - pickings() is a separate function I defined to retrieve the articles. It runs perfectly fine on its own. Please let me know if it needs to be added here.
I got the bot to run. I tried logging as was suggested in the comment above, and there was some error with the way I had imported my modules. The code is fine otherwise.
I am a Python developer, but the circumstances of a project I am working on now, oblige me to find a solution in Node.js
This is the easy python code to send mail but, is there a google app engine way like this in nodejs without use an intermediary service like mailJet or sendGrid?
def send(recipient, sender, subject, body):
isHTML=True
print("recep: "+recipient)
logging.debug(u'Sending mail {} to {}'.format(subject,
unicode(recipient)).encode(u'utf-8'))
message = mail.EmailMessage(
sender=sender,
subject=subject,
to=recipient
)
if isHTML:
message.html = body
else:
message.body = body
message.check_initialized()
message.send()
Thank's for your understanding and help.
The simple example you posted uses the app engine specific Mail API, available only in the first generation standard environment (python 2.7, java 8, php 5.5 and go 1.9 - see the tabs in the referenced documentation page).
Node.js support was added only in the second generation standard environment, which has no such API available.
I was successfully set the Alexa Build steps(checklist) on Alexa Developer Console.
As endpoint I want to use my own remote server(nodeJS, not AWS lambda), I found the next example and trying to use it now:
https://github.com/Glogo/alexa-skill-sample-nodejs-express
By using POSTMAN I can send a JSON with intent to my nodeJS server and successfully get a response.
But once I try to test the flow through Alexa Test Simulator (Test tab in Alexa Developer Console) I don't get any response... On the server side, I can't see any request that comes from Alexa.
I wonder, what is the problem in this case?
Maybe I didn't understand how it should work... I expect to receive a JSON request from Alexa and to output a response.
It's important to mention that I didn't set any properties "Distribution" and "Certification" tabs. As I understand, for testing it's not necessary.
From the screenshot of test simulator, you didn't invoke/launch your skill. Once you launch your skill, a request JSON will be generated by which you can check whether your nodejs server can handle that request.
You can invoke your skill from Test Simulator by:
open, <skill invocation name>
This will trigger a LaunchRequest
You can directly trigger an intent of your skill by,
ask <skill invocation name> <a sample intent utterance>
This will trigger an IntentRequest with the mapped intent
For different invocation phrases, check this.
You first need to open your skill, because the simulator won't open it for you. You can do this by typing/saying
open/start/launch <invocation name>
To trigger one of your intent use
ask/tell <invocation name> <a sample utterance for your intent>
I am trying to deploy an index.js file in the dialogflow. so when I finish the steps if the deployment I am supposed to receive a Project Console and a Function Url. This function url is supposed to be added to the Fulfillment url to get the chatbot running. But I receive only the Project console as can been seen in the screenshot attached.
Anyone has an idea why?