How to get latest bot response in rasa Chatbot? - chatbot

How to get latest bot response with Rasa Chatbot?
For getting user input we use : tracker.latest_message['text']
So, what is syntax for getting latest bot response ?
Thanks

You can use the tracker.events list to fetch the latest bot event.
bot_event = next(e for e in reversed(tracker.events) if e["event"] == "bot")
This will go through the reversed list of events (making it from latest to oldest) and pick the first bot event using the next() function.
The event will be have the following format:
{'event': 'bot', 'timestamp': 1601789469.174273, 'text': 'Hey! How are you?', 'data': {'elements': None, 'quick_replies': None, 'buttons': None, 'attachment': None, 'image': None, 'custom': None}, 'metadata': {}}
There you can simply take the 'text' param if you are only interested in the message.

Related

Adding extra information to Stripe payment intent

I have implemented Stripe in my Flutter app, but I would like to add some information to the payment done in order to recognize the payment inside the payments list inside the Stripe dashboard panel.
This is the response from Stripe when generating a payment:
// 1. Create a payment intent on the server
final response = await http.post(
Uri.parse(
'https://...stripePaymentIntentRequest'),
body: {
'email': email,
'amount': amount.toString(),
'description': widget.codigo_pedido ,
});
final jsonResponse = jsonDecode(response.body);
print("respuests stripe: ${jsonResponse.toString()}");
respuests stripe: {paymentIntent: pi_3M6dBTCcyi0G23rG0FoA7fEl_secret_h6dewQiWveMe5HsPg5MxCduTB, ephemeralKey: ek_test_YWNjdF8xR3NQRm5DY3lpMEcyM3JHLHFiV3ZQRkpBM3VHNHNFOFM3RHJvemxiYlpyaTRSazA_00HIJiGkLl, customer: cus_MqJLygEutMbF4X, success: true}
Is there a way to add some extra information inside the payment intent?
To store additional information on the Payment Intent object, you can add a metadata. Metadata is a key-value pairs that can be attached to an object. To learn more, you review this document.
Your server side code should look something like this:
$stripe->paymentIntents->create(
[
'amount' => 1099,
'currency' => 'usd',
'metadata' => ['order_id' => '6735'],
]
);

Print raw Dialogflow query result fulfillment message

I have the following DialogFlow default and Facebook responses for an intent.
I have a simple Flutter app that calls detectIntent on a DialogflowAPI object that returns a response with query result. I want to print the raw fulfilment messages to console.
...
var response = await df.detectIntent(request, sessionPath);
List<GoogleCloudDialogflowV2IntentMessage> payloads = response.queryResult.fulfillmentMessages;
debugPrint("Got response length: ${payloads.length}");
payloads.forEach((element) => debugPrint(element.payload.toString()));
I get the below console output:
flutter: Got response length: 3
flutter: {text: this is some default text!, replies: [default option 1, default option 2]}
flutter: null
flutter: {replies: [default option 1, default option 2], text: this is some default text!}
There are 3 responses, of which 2 are printed correctly. It does not print the quick replies part of the facebook response.
Each GoogleCloudDialogflowV2IntentMessage has a payload member, which is a json-like Map<String, Object?>. You can print this out:
payloads.forEach((element) => debugPrint(element.payload.toString()));
Alternatively
There is also a toJson() method, which might give you more complete information. You can try printing that as well:
payloads.forEach((element) => debugPrint(jsonEncode(element.toJson())));
Note: you'll need to include import 'dart:convert';.

Paypal Subscription Details Api is giving "Active" status although total cycles complete is 0

I am working with paypal subscription api v1. When an user subscribe to one of my plans on my website, the subscription_id is sent to my server. There I check the status and next billing date using the subscription details api to give the user some value. But when the user subscribes and my server checks for the status, the response it is getting is confusing. The response json is given below:
{'status': 'ACTIVE',
'status_update_time': '2019-11-13T09:36:35Z',
'id': '***',
'plan_id': '***',
'start_time': '2019-11-12T16:00:00Z',
'quantity': '1',
'shipping_amount': {'currency_code': 'USD', 'value': '0.0'},
'subscriber': {'name': **, 'email_address': '***', 'shipping_address': **},
'billing_info': {
'outstanding_balance': {'currency_code': 'USD', 'value': '0.0'},
'cycle_executions': [{
'tenure_type': 'REGULAR',
'sequence': 1,
'cycles_completed': 0,
'cycles_remaining': 0,
'current_pricing_scheme_version': 1,
'total_cycles': 0
}],
'next_billing_time': '2019-11-13T09:36:33Z',
'failed_payments_count': 0
},
'create_time': '2019-11-13T09:35:46Z',
'update_time': '2019-11-13T09:36:35Z',
Here you can see that the status is active but the next_billing_time is less than the status_update_time. And also no payment cycle is completed. Why paypal is behaving like this? I think the status should not be "ACTIVE" if the cycle is not complete. So why is it giving active status?

SugarCRM Rest API: Required fields for a Meeting entry?

I'm trying to create a Meeting entry via the API, but I can't seem to find it in my calendar even though it saved successfully (I got the ID back) and I can see it in the Meetings list.
What fields do I need to populate for it to show in my Sugar calendar? Here are the fields I'm populating:
{
'assigned_user_id': '1', # My user's ID
'date_end': '2013-04-16 01:30:00',
'date_start': '2013-04-16 01:23:45',
'description': 'hello world',
'location': 'JCenter',
'name': 'Test',
'team_id': '1',
'type': 'Sugar' # This doesn't seem to be required
}
Try to set "user_id" and take a look into mettings_users table where you will find it.

Client-side validation with Facebook Registration XFBML

I'm using XFBML embedded in a HTML5 document. I've set up client-side validation following the instructions provided in the "Registration Advanced Uses" doc on Facebook's site, but it only shows errors on blur, and doesn't validate when I click the "Register" button (so if I fill out a field wrong and click outside on another element, it displays the error, but then I can click on the Register button and it registers me anyway).
I've traced it in the JS debugger, and by adding alert/log statements, and my validate_registration function only gets called onblur, and never when I click the Register button.
Anyone seen this behavior and know what I'm missing here? The live example Facebook has on the "Registration Advanced Uses" works perfectly, so I know I've got a mistake somewhere.
My XFBML tag is this:
<div class="fb-registration"
onvalidate="validate_registration"
fields="[
{'name': 'name'},
{'name': 'first_name'},
{'name': 'gender'},
{'name': 'email'},
{'name': 'user_type', 'description': 'Are you a?', 'type': 'select',
'options': {
'parent': 'Parent/Guardian looking for childcare',
'sitter': 'Babysitter/Nanny looking for sitting jobs'
}
},
{'name': 'zip_code', 'description': 'Zip code', 'type': 'text'},
{'name': 'over_eighteen', 'description': 'I am at least 18 years old', 'type': 'checkbox' }
]"
fb_only="true"
redirect-uri="<%= parse_fb_connect_signed_request_users_url %>"
width="530">
</div>
and my validation function is this:
function validate_registration (custom_fields) {
var errors = {},
regexZipCode = /^\d\d\d\d\d$/;
console.log("in validate_registration");
if (custom_fields.user_type !== 'parent' && custom_fields.user_type !== 'sitter') {
errors.user_type = "Select either Parent or Sitter";
}
if ( ! regexZipCode.test(custom_fields.zip_code) ) {
errors.zip_code = 'Enter your 5-digit U.S. zip code';
}
if ( ! custom_fields.over_eighteen ) {
errors.over_eighteen = 'You must be at least 18 years old to use this site!';
}
return errors;
}
So, never mind this.
I was getting the message "You've just registered for X using your Facebook account.
If you didn't mean to do this, you can undo this below." and thought that it meant I had registered. But if I click "Continue" at that point, it shows me all the validation errors, so it does work correctly - it just doesn't validate until after the final step.