Dialogflow CX phone gateway - Extract caller ID - dialogflow-cx

In Dialogflow CX, I have used phone gateway. I want extract the caller ID of the user who calls the voice bot. According to the documentation, we can get the caller id from the payload field in webhook. But I dont see a payload field or caller id in the request in webhook. How can I extract the customer phone number who calls? Thanks in advance.
To understand the problem better, here is the sample code that just prints the contents of the request:
from flask import Flask, request, jsonify
app = Flask(__name__)
#app.route('/webhook', methods=['GET', 'POST'])
def webhook():
req = request.get_json(force=True)
print(req)
if __name__ == "__main__":
app.run(host='0.0.0.0',port=5000)
The contents of the request is attached here

You can retrieve the caller_id value from the payload field in the webhook request. Note that the webhook should be enabled as it’s required to retrieve the telephony field.
Here’s an example webhook code using Node.js to log the caller_id for Dialogflow CX Phone Gateway from your webhook request:
console.log('Caller ID' + JSON.stringify(request.body.payload.telephony));
Result:

Related

How to access webhook payload in Dialogflow CX

I wonder how I can access the webhook payload in the fulfillment tab/dialogue, as I am trying to write it in text to the user.
So, for example a session parameter can be accessed through "$session.params.breakfast", but I am wondering what to write to access a webhook payload. In the webhook payload pictured, I would be interested in accessing the value to the key "hello".

manipulate an existing Dialogflow CX session with a python backend script

I have an existing and functional Chat Bot with Google Dialogflow CX. The Chatbot is directly integrated in a website by the Google Bootstrap.
In some cases a Python script must trigger an intent or page for the user from the backend. In that case the user (and his client) should directly jump in this intent. The session ID of the user is known.
So far I managed it to set a parameter for the user from the python script using the following code.
from google.cloud import dialogflowcx_v3beta1 as dialogflow
from google.cloud.dialogflowcx_v3beta1 import types
session_id = "7826e7-0b7-794-b24-b95271869"
api_endpoint = f"{location_id}-dialogflow.googleapis.com"
client_options = {"api_endpoint": api_endpoint}
client = dialogflow.services.sessions.SessionsClient(client_options=client_options)
event = "live_chat_event"
params = {'message': "Hello World"}
event_input = types.EventInput(event=event)
query_input = types.QueryInput(event=event_input, language_code=language_code)
query_params = types.QueryParameters(parameters=params)
request = types.DetectIntentRequest(
session=session_path,
query_input=query_input,
query_params = query_params
)
response = client.detect_intent(request=request)
print(response.query_result.response_messages[0])
These parameters are then visible by the user on his client, but only after typing the next message.
I need the client to refresh itself or let it jump directly into the next page without any additional input from the user.
How can that be achieved?
Hey bro don't get complicated.
If you are struggling to get the DF API to work you are not the only one.
I can advise you to try the Voximplant Python Client so you can connect to your DF CX Agent easily and control that script . On top of that you can also handle calls with your DF CX or ES Agent.
You can check the documentation to add teh Credentials for DF here.
Also please check this Python API Client so you can run a Scenario that communicates with your CX Agent.

Laravel Slack Notification response

I use the slack notification system from laravel to send messages in a channel.
I would like to access the response of the request to get the timestamp of the message posted to store it and modify the message later.
How could I get this response ?
Thanks !
Actually, I understood that the Slack system in Laravel using the slack webhoock, we cannot get anything in the response.
To get something, we should use the chat.postMessage method instead with a slack token.
There is a package on Github which permit that :
https://github.com/beyondcode/slack-notification-channel

How can I pass a required input from application to Amazon Lex Bot?

I have created a bot with Amazon lex and it's validation & fulfillment with Python and MongoDb.
Bot is working as expected.
Now I am working to integrate my Bot with an ipad application.
Currently my bot asks user about his account id and then bot validate that id in DB and according responses.
Now after integration instead of asking the account id from user, that id should be passed from ipad application to the bot and then bot should responds according.
My question is about this. How can we pass account id from ipad app to bot and then how can my bot or lambda function can get that?
Please suggest if anyone has done similar functionality.
You will want to use requestAttributes or sessionAttributes to pass information like an account ID to your bot with the initial input.
Your bot can then retrieve these from event.requestAttributes or event.sessionAttributes
References: Lex-Lambda Input Event and Response Format
sessionAttributes – Application-specific session attributes that the client sends in the request. If you want Amazon Lex to include them in the response to the client, your Lambda function should send these back to Amazon Lex in the response. For more information, see Setting Session Attributes
requestAttributes – Request-specific attributes that the client sends in the request. Use request attributes to pass information that doesn't need to persist for the entire session. If there are no request attributes, the value will be null. For more information, see Setting Request Attributes
Additional Info
You will want to handle the passing of userInput to your Lex bot yourself in order to include requestAttributes data. To do this, you will need to use PostContent (text or audio input) or PostText (text input only) to send data to your Lex bot.
Your Lex bot will interpret the input and pass along the requestAttributes to your Lambda function, where you can handle the logic based on the Account ID.
Sending user input data as JSON object via PostText:
POST /bot/botName/alias/botAlias/user/userId/text HTTP/1.1
Content-type: application/json
{
"inputText": "Hello Bot",
"requestAttributes": {
"accountID" : "xxxxxxxx"
},
"sessionAttributes": {
"name" : "John Smith"
}
}
To see what Lex will pass to your Lambda Function and how to retrieve the requestAttributes there, see this question where I've answered that in more depth:
AWS Lex Python Codehook references

Bot DirectLine Token Distribute Issue

based on this Bot DirectLine Authentication,
If you plan to distribute the token to clients and want them to initiate the conversation, use the Generate Token operation.
Does this mean we can generate token from backend using Secret and distribute the token to the client for starting a conversation?
To test it, I wrote these:
Backend: #Azure Function
[FunctionName("XXXXX")]
public static async Task<object> RunAsync([HttpTrigger(Route = "XXXXX")] HttpRequestMessage req, TraceWriter log)
{
log.Info($"Webhook was triggered!");
var tokenResponse = await new DirectLineClient(directLineSecret).Tokens.GenerateTokenForNewConversationAsync();
return req.CreateResponse(HttpStatusCode.OK, tokenResponse.Token);
}
and
Client #UWP
// token from Backend
directLineClient = new DirectLineClient(token);
var conversation = directLineClient.Conversations.StartConversation();
weird thing is the variable conversation is null.
When I put the Generate Token code of Backend to Client, it works that the variable conversation is a valid object.
my question is: can we put the Generate Token in backend and distribute token to clients?
my question is: can we put the Generate Token in backend and distribute token to clients?
Of course, if you do not want to expose/share Direct line secret publicly, you can generate Token in backend service and distribute the token to clients and let them to initiate the conversation.
Note: please make sure the Direct Line token generated by your http triggered function is not expired when you use it in your DirectLine Client.
I do a test with DirectLineClient of Direct Line Bot Sample, and modify the code to accept the Direct Line token. If I provide a Direct Line token that is expired, starting conversation will fail.
The problem is that the backend should return token as text media type. much appreciated for your feedback and reminding.
return req.CreateResponse(HttpStatusCode.OK, tokenResponse.Token, "text/plain");

Resources