Python alternative of agent.setContext() - dialogflow-es

In node.js we can set context using agent.setContext(), what will be python alternative of using this way?
Currently I am using below code to set new context:
res = {
"fulfillmentText = "This is a test",
"outputContexts": [
{
"name": "projects/project_id/agent/sessions/session_id/contexts/your_context",
"lifespanCount": 5,
"parameters": {
"foo": "bar",
"foo1": "bar1"
}
}
],
}
return res
Is there any simpler way?
Thanks in advance.
Note : It seems like node.js have dialogflow-fulfillment library to ease up the things. Is there any similar fulfillment library for python as well?

The Node.js dialogflow-fulfillment library is owned and maintained by Dialogflow/Google. There is no "official" Dialogflow Python fulfillment library but there are a couple community efforts you can fork:
Flask extension: https://github.com/treethought/flask-assistant
Response generation helper: https://github.com/pragnakalp/dialogflow-webhook-response-libary-in-python

There is no standard python fulfillment library at this time. Sounds like an opportunity for you!
The format for setting output contexts looks correct, and isn't really much more difficult than the equivalent in JavaScript. How much simpler do you want it?

Related

how to call functions from an npm package I wrote

sorry this is a very basic question. I wrote some functions to handle requests by passing a callback to http.createServer. The functions work if I import them directly from the functions.js file like in this code.
import {handle_request} from './functions.js';
import http from 'http';
http.createServer(handle_request).listen(8080);
Now I want to put this in a package, so that I can install the libraries my code depends on automatically with npm install. My package.json looks like this, I can install the package and I's found in the node REPL, but how do I actually call the functions in the package or use them as callbacks?
{
"name": "package_name",
"version": "1.0.0",
"description": "posts images to a slack channel",
"main": "functions.js",
"author": "me",
"dependencies": {
"mustache": "*"
},
"type": "module"
}
The functions are defined like this:
export var handle_request = function (req, res) {
// function body ...
}
I think my problem is either the import statements in the script that calls the library or some missing exports in the package.
Sorry again for the very basic question, I found many posts and documentations on npm packages but nothing solving my problem. Any help appreciated.
Posting the solution for sake of completeness. There were two mistakes I made:
there's a difference between import mechanisms inside and outside of a module context. The script calling the functions is not inside the module, therefore a using dynamic import is more appropriate.
dynamic import returns a promise, which I missed on an earlier try. In my case this is only called before the server starts, so I can just wait for the promise to be evaluated.
What worked in the end was:
let package_name = await import("package_name");
Thanks for the comment with the link to mdn, this helped a lot.

Azure Function Bindings/Cosmos DB Delete

I am using typescript/node based azure functions with cosmos/sql api. Right now, I have written all my functions logic using the #azure/cosmos client. I am actively trying to refactor those functions to use input/output bindings instead; however, I am having issues finding examples of deleting entities using bindings.
Example input binding:
{
"type": "cosmosDB",
"direction": "in",
"name": "inputDocument",
"databaseName": "test",
"collectionName": "test",
"connectionStringSetting": "COSMOS_DB",
"id": "{id}",
"partitionKey": "/tenantId",
"sqlQuery": ""
}
So, to simplify things, my questions are:
Can bindings be used to perform delete operations?
Is there a way to elegantly inject an #azure/cosmos client in typescript using function bindings? I saw some examples in C#, but I could not find anything typescript related.
Any advice/suggestions would be greatly appreciated! Thank you so much :)

byte-range-requests in nestjs

I was searching the internet for hours on end hoping to find any kind of built-in functionality to support byte-range requests (https://www.keycdn.com/support/byte-range-requests) within nestjs. I am coming from the .NET world where we have got something like this:
[Route("/streams/{id}")]
public IActionResult Clip(string Id) {
... more code ...
return File(myDataStream, "video/mp4", enableRangeProcessing: true);
}
Is there any analogous, similiar or comparable functionality within nestjs which I had then simply overlooked or do I really have to develop this rather cumbersome yet pretty common use-case on my own?
Kind regards
Samuel

How do I find Azure ARM template output properties for a resoruce

When writing the outputs part of ARM template how do the do what properties are available for a resource. in the below example for public ip resource how do I find out dnsSettings.fqdn or .ipAddress is available
"outputs": {
"fqdn": {
"value": "[reference(parameters('publicIPAddresses_name')).dnsSettings.fqdn]",
"type": "string"
},
"ipaddress": {
"value": "[reference(parameters('publicIPAddresses_name')).ipAddress]",
"type": "string"
}
}
Your ask is related to Retrieve FQDN of Azure SQL from a linkted template question.
The easiest way to accomplish your requirement is illustrated in below screenshot.
Hope this helps!! Cheers!!
Note: If you think your question has been answered then please 'accept' it, if just helped then click "This answer is useful" and provide an up vote. This can be beneficial to other community members reading this thread.
One way I've found, using only ARM, is to output the whole object:
"outputs": {
"ipaddress": {
"type": "Object",
"value": "[reference(parameters('publicIPAddresses_name'))]"
}
When you apply the policy, the output will show all the possible properties and their values.
You can view the whole data structure in json at https://resources.azure.com.
you dont really know, because some properties are amended by default (and the other answer doesnt mention that at all, which could mislead you badly). One thing you can do is look at the rest api definition of the resource and use Full reference to the resource, that way you will always get what you see in the api definition.
reference(parameters('publicIPAddresses_name'), 'api-version', 'Full')
but, object structure will be different, as far as I remember you'd need to access properties of the object for the most of the output. What I tend to do is - create a template that does nothing but output the existing object I'm interested in and run it and examine the output.
Outputs are almost never needed so it's not that big of an issue in my mind.
Rest Api definitions: https://learn.microsoft.com/en-us/rest/api/azure/

Using Puppet to install Azure client to all nodes

​First, sorry for asking basic and quite silly questions.
I'm very newbie and do not have much experience in this kind of operation.
I have read many documents from official site, tutorialspoint(gave me basic concepts of how puppet work) site and else but still confused and don't know where to start.
Since I wanted to install Azure to all slave nodes, I think I have to create classes like
class packages {
# the first, most obvious solution is
package { 'screen': ensure => 'installed' }
package { 'strace': ensure => 'installed' }
package { 'sudo': ensure => 'installed' }
# you can use a global package parameter
Package { ensure => 'installed' }
package { 'screen': }
package { 'strace': }
package { 'sudo': }
# you can specify the packages in an array ...
$enhancers = [ 'screen', 'strace', 'sudo' ]
package { $enhancers: ensure => 'installed' }
# ... and even combine it a global package parameter
Package { ensure => 'installed' }
$enhancers = [ 'screen', 'strace', 'sudo' ]
package { $enhancers: }
}
cr: https://www.puppetcookbook.com/posts/install-multiple-packages.html
But hey! where should I put that code to ?, How can I execute that? they do not tell me T-T
I really appreciate for all your kindness and your answers
Thanks
Edited on 26th Mar 2019
Thanks for all the comments, I've read for the architecture and be able to create a class now.
Note that The Puppet Cookbook goes back to the days of Puppet 3. It can still be useful, but it predates modern language features like iteration and data types, and no longer aligns with modern best practices.
Nowadays, I rarely see packages grouped into a class like this by the way. Often, packages are externalised in Hiera as data and read into a class, perhaps a "configure" or "install" class, via a packages parameter. (Not that I'm suggesting there's anything wrong with having a packages class.)
To the main part of your question:
But hey! where should I put that code to ?, How can I execute that? they do not tell me T-T
To learn more about how to organise your classes, you need to learn about the Roles and Profiles pattern.
UPDATE: As pointed out in the comments, you may be confused about more basic things than how to organise your classes. At this point, I should say that Stack Overflow is a site for asking specific questions that have a specific answer.
Do have a look at this page here. My suggestion is to follow the advice in there and join the Puppet Community Slack. People in that forum will be glad to help you get started and answer your questions in real time.

Resources