question

newuser-28cc618a-2d29-4ff2-8a92-a82955101750 avatar image

Reference for CanfulfilIntentRequest in Python

Hi There,

I'm trying to implement CanFulfilIntentRequest in pyhton and trying to get some sample code. Is there any sample code available?


Thanks.

canfulfillintentrequest
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-28cc618a-2d29-4ff2-8a92-a82955101750 avatar image
newuser-28cc618a-2d29-4ff2-8a92-a82955101750 answered

I've got CanFulFIlIntentrtequestHandler as below. But I'm not sure how that will redirect to appropriate intent.

class CanFulfilIntentHandler(AbstractRequestHandler):
    """Handler for can fulfil handle intent."""

    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return is_request_type("CanFulfillIntentRequest")(handler_input)

    def handle(self, handler_input):
        fulfilintent = CanFulfillIntent(True)
        handler_input.response_builder.set_can_fulfill_intent(fulfilintent)
        return handler_input.response_builder.response

request which I'm sending(code fragment) is

"request": {
   "type": "CanFulfillIntentRequest",
   "requestId": "amzn1.echo-api.request.7bb9c640-f0fd-4c7e-xxxxxxxxxxx",
   "timestamp": "2019-06-08T13:52:37Z",
   "locale": "en-US",
   "intent": {
      "name": "WifiIntent",
      "confirmationStatus": "NONE"
   },
   "dialogState": "STARTED"
}

and the response I get is

 'response': {'canFulfillIntent': {'canFulfill': True}}}

so my question is how can I get this request to the intent 'wifiIntent'?

Any pointers will e of great help.

Thanks heaps.

8 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rokas avatar image Rokas commented ·

Read more here how CFIR work in more detail: docs. Overall if you mark that you can fulfil 'WifiIntent', then if Alexa decides that your CFIR is the best, she will invoke that intent. Basically, what intent you mark that you can fulfil, that intent will get invoked.

Here is the example, even though it is written in JS, but I think it can help you to get a sense how it works.

1 Like 1 ·

Thanks for that. I've got that going and appropriate intent is invoked when testing using Json in Developer console.

However my problem now is that it is not getting invoked from the device without invocation name.

My skill works fine with the echo device with name invocation. But it is not getting any CanFulfillI requests.

Is there more config required?

Cheers


0 Likes 0 ·
Rokas avatar image Rokas newuser-28cc618a-2d29-4ff2-8a92-a82955101750 commented ·

Well, even if you have added CFIR, it doesn't mean that it will get invoked always. CFIR is used more as a fallback for alexa. If she doesn't find an exact match to the command user gave, she'll send CFIR to some skills, to see if any of them can handle it and only then, your skill might get chosen, but might not. So yeah, it could get invoked, but chances are pretty slim.

1 Like 1 ·
Show more comments
newuser-28cc618a-2d29-4ff2-8a92-a82955101750 avatar image
newuser-28cc618a-2d29-4ff2-8a92-a82955101750 answered

Ok, to answer my own question, I check for the intent name in the handle() method and call the appropriate handler.

intent_name = handler_input.request_envelope.request.intent.name
if (intent_name == 'xxxIntent'):
    return xxxIntentHandler.handle(self, handler_input)
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.