So I have been building a chatbot powered by RASA stack (open source).
After creating the bot, I wanted to integrate it with our web application. Now I'm able get responses from my RASA core but I'm in a problem. I'm passing a unique user_id in the GET request which i need to fetch inside a python function and call an external API to my Database. But I don't know how to fetch that parameter out from GET request. here are some details.
My GET request: (I uploaded my bot on AWS server)
http://my_ip_.amazonaws.com:5005/conversations/27/respond?q=%27Hi
So my unique id is 27 which i want to fetch inside a python function.
and the response i'm getting by this request :
[{“recipient_id”:“27”,“text”:“Hey! What can I do for you?”}]
As you can see I passed the GET request in postman and got this response from my RASA CHATBOT but I want to track this user-id 27.
So my question is how can I track this id? Or maybe you guys can suggest me another way to do it.
Thanks for your help in advance :) My first post BTW :)
[Please ask me anything if you feel this question is missing something]
So you are receiving the following data from the request:
[{“recipient_id”:“27”,“text”:“Hey! What can I do for you?”}].
If it's a list:
just use:
response = [{“recipient_id”:“27”,“text”:“Hey! What can I do for you?”}]
recepient_id = response[0]['recipient_id']
If it's a dict:
response = {“recipient_id”:“27”,“text”:“Hey! What can I do for you?”}
recepient_id = response['recipient_id']
so I solved this issue by using tracker data. Actually, I had to link tracker dictionary to my custom action file so that I can access the sender_id and other slot values.
I used:
user_id = tracker.sender_id
parameters ={}
parameters = {"user_id": user_id}
then it follows by my post request and it works! Thanks
Related
I am attempting to retrieve and add function/host keys for an Azure Government function app via Python. I am currently working with the information from this question and the corresponding API page. While these are not specific to Azure Government, I would think the process would be similar after updating the URLs to the Azure Government versions. However, I am receiving the error "No route registered for '/api/functions/admin/token'" when running the jwt part of the given code. Is this approach feasible for what I am trying to do?
I also found somewhere that I instead might want to try a GET request like this:
resp = requests.get("https://management.usgovcloudapi.net/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Web/sites/<function-app-name>/functions/admin/masterkey?api-version=20XX-XX-XX", headers={"Authorization": f"Bearer {something}"})
This gives me the error "{"error":{"code":"InvalidAuthenticationToken","message":"The access token is invalid."}}", though. If this is indeed the correct approach, then what format should the Bearer token take?
Bit late answering but it may be useful for someone else in the future, it took me a while to find out how to do this.
If you want to retrieve the keys of a specific function within a function app then you can use list_function_keys() function from the Python SDK
Working with the Az management API directly may be a bit annoying and since the Azure CLI is written in Python whatever operation you do with the CLI you can do it directly in a Python script.
Here's an example of how you can retrieve the keys
from azure.identity import DefaultAzureCredential
from azure.mgmt.web import WebSiteManagementClient
# Your subscription ID
SUB_ID = "00000000-0000-0000-0000-000000000000"
fn_name = "some_function" # Name of your function
app_name = "some_app" # Name of your site/function app
rg_name = "some_rg" # Resource group name to which the function belongs
web_client = WebSiteManagementClient(subscription_id=SUB_ID, credential=DefaultAzureCredential())
keys = web_client.web_apps.list_function_keys(rg_name, app_name, fn_name)
# Your keys will be accessible in the additional_properties param
print(keys.additional_properties)
Hope it helps! I'm new on Azure so if I'm doing something wrong, please don't hesitate to point out my mistake and share your correction
I have been attempting to use PyGitHub to edit/update my repository files using PyGitHub, however (I guess I tried to access it too many times :P) it gives me this error:
github.GithubException.RateLimitExceededException: 403 {"message": "API rate limit exceeded for xx.xx.xx.xxxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", "documentation_url": "https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}
I was accessing the data just fine before. I had researched it and in the effort to fix the problem I had replaced my username with an access token. Here is my full code:
from github import Github
# Github username
username = "JosephCWatkins"
password = yeoldepasswordhere
# pygithub object
g = Github(yeolaccesstokenhere, password)
user = g.get_user(username)
repof = g.get_repo("JosephCWatkins/moonspellprojectprogress")
#me trying to access the data :P:
contents = repof.get_contents("test.txt")
print(contents.content.split.__doc__())
It says that I must authenticate myself which would give me a higher rate limit, but the best I could figure out on trying to solve it was adding the access token. Am I doing something wrong? How can I authenticate myself so I can continue working with the API? And also, if you could help me be able to print the contents of a repository file. Thank You. :)
The first part of my question is still unanswered, but I accessed the contents of my GitHub Repository File with this code:
repo = g.get_repo("username/repositoryname")
contents = repo.get_contents("filename.filetype").decoded_content
I know it sounds simple but the documentation does not go into the various functions like it should, it mostly only gives examples. Plus the internet lacks a simple answer to this problem. For anyone who wants to access their GitHub file via PyGitHub, here it is.
I want to send information back-end via JS to update the database based on user response, but I don't need a JSON response or other HTTP rendering done.
It's a test type app so all I'm sending back is a single identifier (integer) and boolean value to indicate pass/fail on their response.
Currently I am using a fetch(url/${identifier}/bool) and all works as intended with the data management, but Python/Django throws an error as I am not returning any value.
So I have two questions.
Is fetch the right way of doing this as I am not actually expecting a response and I am doing no manipulation JS side with the data after calling it.
How can I stop Django from expecting a response on this as I intend to run the call as a simple function rather than an API call with JSON response sent back.
Thank you for the help.
Fixed the issue by simply using
return HttpResponse(status = 200)
I am trying to get my python slack bot to work. I want to get the info of the user who is trying to make API calls using users.identity API. However, I was unable to make it to work.
Any tips and idea why?
This is the error I get.
Thanks in advance.
It won't work on https://api.slack.com/methods/users.identity/test. But if you create an "app/script" where you can authenticate and then request with https://slack.com/api/users.identity?token=xxx you will get a valid response for the logged in person. With User Name,User id and Team id
The variable cherrypy.request.params as it is described in the API contains the query string and the POST variables in a dictionary. However combing over this, it seems that it contains every variable received after processing the full request URI to pull the GET data. This then becomes indistinguishable from POST data in the dictionary.
There seems to be no way to tell the difference, or perhaps I am wrong.
Can someone please enlighten me as to how to use purely posted data and ignore any data in the query string beyond the request URI. And yes I am aware I can find out whether it was a POST or GET request but this does not stop forgery in requests to URIs containing GET data in a POST request.
>http://localhost:8080/testURL/part2?test=1
>POST username = test
"cherrypy.request.params" has 2 variables
test = 1
username=test
The docs aren't very clear on this point, but starting in CherryPy 3.2, you can reference request.body.params to obtain just the POST/PUT params. In 3.2 and below, try request.body_params. See http://docs.cherrypy.org/dev/refman/_cprequest.html#cherrypy._cprequest.Request.body_params