PHP Fatal error

On Calling he website http://localhost/api.ai/webhook

it returns {"status":{"code":405,"errorType":"Method Not Allowed"},"speech":"An error occurred."}

Php error log shows: PHP Fatal error: Class 'ApiAi\Model\Query' not found in x:\xxxxxx\api_ai_webhook\src\ApiAi\Model\Webhook\Request.php on line 17

CommentFileSizeAuthor
#4 cahtbotAPI.png10.1 KBtkrishnapriya
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tkrishnapriya created an issue. See original summary.

tkrishnapriya’s picture

Title: Failing to handle api_ai_webhook\src\ApiAi\Model\Webhook\Request.php: PHP Fatal error: Class 'ApiAi\Model\Query' » Failing to handle api_ai_webhook\src\ApiAi\Model\Webhook\Request.php: PHP Fatal error: Class 'ApiAi\Model\Query' not found
Issue summary: View changes
gambry’s picture

It looks like the ApiAi library is not found. Did you include it either by installing the module through composer or in any other way?

tkrishnapriya’s picture

FileSize
10.1 KB

I am adding image attachments in support where i have included all libraries that is installed and enabled. But in-fact i have not used composer to do so. Is composer vital in installing those modules. I don’t receive proper json response on call to localhost/api.ai/webhook. And i am unable to use Entity Collection interface as well and it returns

[php7:notice] [pid 5188:tid 1784] [client ::1:53600] Uncaught PHP Exception UnexpectedValueException: “In order to use the api.ai remote entity push, you need to add your developer token to settings.php. E.g. $settings[‘api_ai_webhook_developer_token’] = ‘your token here’.
modules\\api_ai_webhook\\src\\Plugin\\ChatbotApiEntities\\PushHandler\\ApiAiPushHandler.php line 142, referer: config/service/chatbot-api-entity-collection/add

gambry’s picture

Hi @tkrishnapriya . The ones in your image are the modules, no the PHP libraries required.

If you check the main page of this module, it says:

Installation

Dialogflow Webhook requires the PHP library iboldurev/api-ai-php. If you have a composer-based project you are covered, otherwise you'll need download and autoload it manually.

Check Installing modules' Composer dependencies and also Using Composer to manage Drupal site dependencies for some approaches on how to handle this.
External dependencies is a Drupal thing, not Chatbot related, so by learning this you will be ready next time a module requires external dependencies.

RE: Entities, please follow what the error is saying, so get your developer key from Dialogflow and add them to the settings.php as explained.

tkrishnapriya’s picture

Hi, Correct i didn't include iboldurev/api-ai-php php library earlier , but now i have used composer to get the libaray. Now i have iboldurev/api-ai-php php folder is at root of my drupal installation in vendor folder i.e. drupal/vendor/iboldurev/api-ai-php php. But still facing the same issue.
{"status":{"code":405,"errorType":"Method Not Allowed"},"speech":"An error occurred."}
Any other issue that might be the cause. What else do i needd to provide for your reference for better understanding the issue here with me.

tkrishnapriya’s picture

Now i am able to add entities and added developer key from Dialogflow and add them to the settings.php.

tkrishnapriya’s picture

Still i have iboldurev/api-ai-php php folder is at root of my drupal installation in vendor folder i.e. drupal/vendor/iboldurev/api-ai-php php. But still facing the same issue.
{"status":{"code":405,"errorType":"Method Not Allowed"},"speech":"An error occurred."}

Entity collections are added in Drupal as of now but still it is not pushed to Dialogflow console after running cron also

gambry’s picture

@tkrishnapriya you may have composer require iboldurev/api-ai-php without specifying the version.
The owner of the library changed the namespace root from ApiAi to Dialogflow, so unless you don't require version 0.2.5 you will keep getting that error. There is an issue to upgrade to the new package: #2919447: Migrate to iboldurev/dialogflow package

If that's the case please try composer require iboldurev/api-ai-php:0.2.5.

Entity collections are added in Drupal as of now but still it is not pushed to Dialogflow console after running cron also

You need to give more info about this:
- Are you using Dialogflow API V1?
- Any error in the logs?

tkrishnapriya’s picture

Hi, Actually i had installed iboldurev/dialogflow library, after your comments i installed iboldurev/api-ai-php so both were available. And now i have precisely made it to iboldurev/api-ai-php:0.2.5 and iboldurev/dialogflow is also there.

Regarding Entity collection, I have been using Diglogflow V1 only.

Now as of now i am not seeing any error logs. I am unable to find the flaw.

I find the JSON response being returned by api_ai_webhook\src\EventSubscriber\ResponseEventSubscriber.php

gambry’s picture

And now i have precisely made it to iboldurev/api-ai-php:0.2.5

So is this now working as expected I presume?
Let's fix this issue first, and then we move to the other one.

RE the Entities all you need is really the Entities in drupal and the developer key on settings.php, and after the configuration entities should me pushed on cron.
If this is not working I'm afraid you have to dig and debug a bit more and tell me what's going on. I've build a bot last week and didn't have any issue so I'm quite confident things are working.

tkrishnapriya’s picture

Yeah, i have precisely made it to iboldurev/api-ai-php:0.2.5 but on accessing the http://localhost/api.ai/webhook i get the JSON response

{"status":{"code":405,"errorType":"Method Not Allowed"},"speech":"An error occurred."}

Which is coming from the location api_ai_webhook\src\EventSubscriber\ResponseEventSubscriber.php

tkrishnapriya’s picture

I have re followed all steps and while trying to add entity collection I am seeing in error logs

Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "Error getting list of existing remote IDs for Chatbot API entity collection Languages on API.ai" at \modules\api_ai_webhook\src\Plugin\ChatbotApiEntities\PushHandler\ApiAiPushHandler.php line 213.

I am unable to figure out what i am missing. If a elaborated steps for just a sample demo will be very helpful to proceed to play around it.

gambry’s picture

{"status":{"code":405,"errorType":"Method Not Allowed"},"speech":"An error occurred."}

Which is coming from the location api_ai_webhook\src\EventSubscriber\ResponseEventSubscriber.php

You need to report the error too. If the error is still "Class 'ApiAi\Model\Query' not found" the class is not found. So either the class is still missing from the file system (unlikely) or you are not auto-loading the class correctly (most likely).

I have re followed all steps and while trying to add entity collection I am seeing in error logs

Before this error watchdog should have another log entry with more info.
The error is due something wrong with the request, out of my mind the only things I can think of are Dialogflow agent is not setup for V1 (I know you said it is, but please double check) or the entered developer key value is not correct.

gambry’s picture

on accessing the http://localhost/api.ai/webhook i get the JSON response

{"status":{"code":405,"errorType":"Method Not Allowed"},"speech":"An error occurred."}

Worth mentioning you can only POST to /api.ai/webhook , and you should post a valid JSON only (you can get it from Dialogflow console).

tkrishnapriya’s picture

Hi, Everything is working fine now i followed the steps afresh.

I am having two issues:

1. But Synonyms are being added as separate entity or term to the API.ai console. What do i need to do to make synonyms for a term to be not treated as separate term.

2. When testing the in Console with intent message : "Can you fix my boiler"
I am asked to enter Account ID : after entering abc123 dummy characters it did not return nothing "Not Available"

where as in Diagnostic Info, I see this:

"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: Request timeout."
},

gambry’s picture

Status: Needs work » Closed (works as designed)

1. But Synonyms are being added as separate entity or term to the API.ai console. What do i need to do to make synonyms for a term to be not treated as separate term.

They should not be treated as separated entities, unless you've configured to do so. Check your configuration

When testing the in Console with intent message : "Can you fix my boiler"
I am asked to enter Account ID : after entering abc123 dummy characters it did not return nothing "Not Available"

You are probably using the example agent I made for the DrupalCampLondon presentation. You may need to enable the module drupalcamp_london.

Also be aware that is an example module, I'm confident it works but I'm not 100% sure it does on every environment out of the box.

As your issue now looks like fixed and yours are integration issues (outside the scope of this issue or module) I'm closing this one.
Feel free to open new issue related to this module, but please make sure first they actually belong to here, or to Chatbot API, or your configuration.

Thanks for helping by using the module!

tkrishnapriya’s picture

Yes Sure it can closed. I am able to communicate with Dialogflow. Thanks for coping and replying.

apaderno’s picture

Issue tags: -PHP Fatal error: +PHP fatal errors