Unable to extract log from watson assistant - python-3.x

Please I have struggling with consuming watson assistant log API. currently we use watson assistant log API for fetching daily conversation log between our chatbot and customer and feed the log into NLC for classifying the intents for precision analyst. Recently we observed that IBM has decomission the NLC and advice that we migrate to NLU. since then we've being having issues getting the component running.
right now the assistant log return empty log for this filterĀ 
authenticator = IAMAuthenticator('********')
assistant = AssistantV2(
version='2021-06-14',
authenticator = authenticator
)
assistant.set_service_url('https://api.eu-gb.assistant.watson.cloud.ibm.com')
print("The assistant URL ")
response=assistant.list_logs(
assistant_id='******', page_limit=100, filter='response_timestamp>2022-09-14T00:00:00.000Z',
cursor=cursor).get_result()
response=assistant.list_logs(
assistant_id='*******').get_result()
print(json.dumps(response, indent=2))
#print("the response is ",response)
this is returning an empty data
{
"logs": [],
"pagination": {}
}

Here are some reasons why this may occur.
You are using V2 API which requires an Enterprise account. If you only have Plus then you can use the V1 API. But there is no guarantee it will continue to work as expected in the future.
You don't have any logs for that date range. Check in the Analytics page.
An issue in your code. Try running the sample code on the REST API docs. If this works then compare against your code.
Your filter looks ok, but try this filter (change language and assistant ID):
language::en,request.context.system.assistant_id::<YOUR_ASSISTANT_ID>,response_timestamp>2022-09-14T00:00:00.000Z
Seeing as you have midnight as your time, you can also change that part to:
response_timestamp>2022-09-14

Related

Azure Get Video Index or Get Project Index API response body is blank

This is about Azure Video Indexer API. I am using a trial account. (Using Corporate account to log in to the Video Indexer portal but using a trial, not a paid account yet). I uploaded a few videos using Indexer Portal. Then I am trying to use the Video Indexer API to get video index. The Get Video Index (or Get Project Index) APIs give proper response when called through the "Try it" panel of the Developer Portal. But when exactly same Get API is called through Java code, the response is blank. The response status is 200 OK. Response header also shows valid header as follows:
[Content-Length:"13052", Content-Type:"application/json; charset=utf-8", x-ms-request-id:"a747d33c-a1e8-444d-89ce-d49a531507c2", X-Content-Type-Options:"nosniff", Strict-Transport-Security:"max-age=31536000; includeSubDomains", api-supported-versions:"2.0", Access-Control-Allow-Credentials:"true", Date:"Thu, 27 Oct 2022 15:19:53 GMT"]
But response body just doesnt print anything.
(Just to repeat, the same Get API call works fine from the "Try it" panel using same/similar access token etc. But when called through Java code, it doesnt give back any response, not any error).
Any help would be highly appreciated.
I have already tried using the readily available Java code snippet provided in the "Try it" panel. But same behaviour.
Thanks.
mrisbud

How to limit the number of chats received in chatbot Kommunicate

I have integrated Kommunicate chat bot into my website, however, a lot of traffic is generated on my website, due to which a lot more users are chatting than I have the bandwidth to support (agent wise).
I can't seem to find a way to limit the number of currently active chats one agent/human can handle at any given time. I wish to find a solution for the same.
Can this be done through the webhook integration provided? If so, how?
The solution indeed lied in adding the webhook integration.
First, I spin up a simple flask server, serving a single endpoint: /webhook.
app = Flask(__name__)
#app.route('/webhook', methods=['GET', 'POST'])
def webhook():
logger.debug('Webhook Triggered') #-> we know it's being trigerred.
resp_generated = make_response(jsonify(results()))
logger.debug(resp_generated)#-> always shows 200 anyway.
return resp_generated
if __name__ == '__main__':
app.run(host ='0.0.0.0', port = 5000, debug = True)
Then I use ngrok to create a tunnel to my local server (I plan to host it on GKE in the later stages)
ngrok http 5000
This gives me an HTTPS URL to my Flask server such as https:\\534bbe.ngrok.io
Then I go into DialogFlow -> Fulfillment -> Enter my Webhooks endpoint there:
[Note: Hit the save button at the bottom of the page]
You would have to enable webhook call for the Intents on which you are going to add your server logic, in my case it was when I wanted to transfer to a live agent while limiting the number of chats:
To ensure that the default behavior of Kommunicate is not broken when my server goes down, I have added custom payload (as shown in the image above):
{
"metadata": {
"KM_ASSIGN_TO": ""
},
"platform": "kommunicate",
"message": "---- Redact that sweet sweet company Information. Yeah!!---"
}
[Note: Make sure to hit Save on the top right, once you make your changes in the Intent.]
Then I added the Webhook URL (same as the one used in DialogFlow) in Kommunicate -> Settings -> Developer -> Webhooks
[Note: Hit the save changes button at the bottom of the page]
Once everything is set up, you will start receiving messages in the server and can add your logic as you wish. Do note that this is super tedious as you would have to read a lot of documentation and add a bunch of logic to get it to work as you want it to.

I want to send platform specific responses using dialogflow fullfilment

I built a bot that is integrated to messenger and default bot on website using dialogflow now the bot have default response and messenger response but when I go to the fullfilment i cant set a specific response for each
here is my code
function time(agent) {
if (currentlyOpen()) {
agent.add(`Hi, We're open now! We close at 11pm today.`);
} else {
agent.add(`We're currently closed, but we open every day at 6am!`);
}
}
I want to have a diffrent response if I am using messenger as the default response goes to the default bot
"I know I can inrtegrate messenger in the website but I want to know this way as I use it for more bots"
You can do that using the same library that you are using for agent. To send specific platform response just add the platform to the response. For example, if you want send a text specifically to Google Assistant then you can do that using agent.add(new Text({ text: 'text_here', platform: 'ACTIONS_ON_GOOGLE'}));.
The full Dialogflow fulfillment code is available on GitHub. https://github.com/dialogflow/dialogflow-fulfillment-nodejs. I have also modified some code to set some other responses that are not available in this library such as telephony transfer and speech responses. So, if you want you can do that too.

Is it possible to lookup a database in a Dialogflow intent?

I'm trying to make an app using DialogFlow which finds a specific object in a specific place.
This is a generic example.
The user would say something like "Where to I find Dog in Europe" and the app would reply with "Dog can be found in Europe via: breeding, finding it out in the wild or by buying it"
considering Dog as input1 and europe as input2
Ideally the app should be able to cross reference input1 and input2 to find the correct response. Can I implement a database like structure and do this?
You can't access a database from Dialogflow directly, but you can build your own fulfillment backend that can do anything you want. It communicates with Dialogflow via HTTP requests/responses in the Dialogflow Webhook format.
Here is an example fulfillment that reads data from Firebase database - https://github.com/actions-on-google/dialogflow-updates-nodejs
You can't access a database directly in Dialog flow, but you can build your own fulfillment back end. I have been using Airtable as a database and Integromat and Webhooks to query the database and parse the results back to Dialogflow. As a novice coder I found this to be the simnplest way.
KaySubb is right, you can make a fulfillment that reads data from a firebase database(or firestore).
You can do this turning on fulfillment at the bottom page of the intent page.
First go to https://console.firebase.google.com/ (login with google account) and you should be able to see your google cloud platform project.
To use firebase, you need to first install it. Get node.js as you need npm first. I'm not sure what OS you're on but go into command line or terminal and type.
npm install firebase --save
then type:
firebase login
this will authenticate your login and connect your project when you deploy.
Then use go to the directory you want to create your project in:
firebase init functions
Select your project and select javascript, install all dependencies
Now go to functions and open the index.js file. Here you can change you write code needed in js.
Write your functions and type:
firebase deploy
in the command line open in the file directory. When it completes, it will
give you a link. This as the webhook URL in dialogflow (it should start with
https://us-central). If you see only 1 link which says
console.firebase.google.com....... then open that link on a browser, click on
"functions" on the left side of the screen and get the link from there.
This should get you started with firebase, now you can link your project to firebase fulfillment. There is great firestore explanation here
https://www.youtube.com/watch?v=kdk6MhhI8oc
But I'll give you a brief explanation:
On the top of your index.js file you will need:
const functions = require('firebase-functions');
var admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
var firestore = admin.firestore();
The basic code is here:
exports.webhook = functions.https.onRequest((request, response) => {
switch(request.body.result.action){
case 'saveData':
let params = request.body.result.parameters
firestore.collection('colName').doc('docName').add({
name:params.name
age:params.age
}).then(() => {
response.send({
speech:
`this is a response for "${params.name}".`
});
})
.catch((e => {
console.log('Error getting documents', e);
response.send({
speech:
`Sorry, something has gone wrong. Try again and if the problem persists, please report it.`
});
}))
break;
default:
}
})
I'll explain what it does:
You need the switch to decide which intent to do. request.body.result.action returns the action name (write this in dialogflow just above the parameters).
Once that is decided request.body.result.parameters give you the parameters from the intent. params.______ gives you the parameter.
I would definitely recommend reading the official documentation:
https://firebase.google.com/docs/firestore/quickstart
to help understand the data structure to help create the ideal database for you. Essentially a collection is a list and within that a doc is one entry. You can name them yourself of using the entries from param.
respond.send is what the bot will reply to the user, I've also shown how to use the parameters in the response.
.catch will just store any errors in the log, you can read the log in console.firebase.google.com.... open your project and click on function. There will be a place to read logs there. You can check any errors encountered over there.
default: will output whatever default response you wrote on dialogflow at the bottom of the intent.
Hope this helps,comment any questions. I have gone through a huge amount as concisely as I could. This will take some time to get used to and become good at, follow the docs and the youtube videos if you have a lot of trouble!
If you're having even more trouble, there is a slack that helps people that I can direct you to.

Azure Logic App - Twitter Connector Issues

I have a Logic App with Twitter connector and a Dropbox connector. The latter has repeater, which loops over the Twitter body and upload a text file in each iteration with Tweet_ID as file name. The Dropbox connector many times returns conflict errors, it seems Tweet connector keeps returning same tweets again and again, which had been already processed, which results in duplicate file names.
When I look at the output of the Dropbox connector, below is the body it returns.
"body": {
"status": 409,
"source": "api-content.dropbox.com",
"message": "conflict_file"
}
You have probably seen this page https://azure.microsoft.com/sv-se/documentation/articles/app-service-logic-use-logic-app-features/ where they show how to do this.
Have you checked that you don't supply the same Tweet_ID several times? The logic app json format it a bit tricky right now, with not so much documentation.
/dag
You are right. The twitter connector doesn't "remember" the tweets that are returned from a search. It will return the same again. (Just to be clear. We are discussing the Twitter Connector Action Search Tweets.)

Resources