Webhook Plugin - a bit of assistance needed.

More
1 year 2 months ago #142442 by web_digital
web_digital created the topic: Webhook Plugin - a bit of assistance needed.
Hi

I'm trying to create a plugin that will allow the user to specify a webhook that fires on the afterSurveyComplete event.
I'm an "ok" developer, but this will be a good challenge for me!

So far so good .... using the example plugins I have created the plugin and added the custom field to the survey.

Next is to retrieve the custom field value so it can be used by the afterSurveyComplete event.
I have had a good scan of the api docs, but no luck so far.
Its seems like i need to use a get method, something like this: get("webhookurl","Survey",$surveyId), but i'm not clear on what object I should be using.

Can anyone offer any help please?
Many thanks

Mat.

Please Log in to join the conversation.

More
1 year 2 months ago - 1 year 2 months ago #142444 by DenisChenu
DenisChenu replied the topic: Webhook Plugin - a bit of assistance needed.
Hi,

In your function :
- $this->getEvent()->get('surveyId'); give you the surveyId
- $this->getEvent()->get('responseId'); give you the responseId

And for your settings :
$this->get('yoursetting', 'Survey', $this->getEvent()->get('surveyId'),'defaultvalue') if it's by survey
$this->get('yoursetting') for the global setting

See github.com/LimeSurvey/LimeSurvey/blob/ma...ShowResponse.php#L21

And a really more complicated example here : github.com/SondagesPro/LS-sendPdfReport/...ndPdfReport.php#L174

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 1 year 2 months ago by DenisChenu.
The following user(s) said Thank You: LouisGac

Please Log in to join the conversation.

More
1 year 2 months ago #142446 by web_digital
web_digital replied the topic: Webhook Plugin - a bit of assistance needed.
Bingo .... after a quick break, realized I needed to pass the plugin object too with get:

$store = $this->getStore();
$url = $store->get($this,"webhookurl","Survey",$surveyId);

Please Log in to join the conversation.

More
1 year 2 months ago #142447 by web_digital
web_digital replied the topic: Webhook Plugin - a bit of assistance needed.
Thankyou DenisChenu - will have a look at your suggestions too! cheers.

Please Log in to join the conversation.

More
1 year 2 months ago #142463 by DenisChenu
DenisChenu replied the topic: Webhook Plugin - a bit of assistance needed.
You rewrite the libraries, it surely can be improved, but best is to improve it in LS core ;)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 year 2 months ago #142483 by web_digital
web_digital replied the topic: Webhook Plugin - a bit of assistance needed.
Had a crack at the plugin - its working but needs a bit of tidying up.
github.com/mrcandu/limesurvey-webhook/blob/master/WebHook.php

The manual refers to a "log" method being available in 2.5, but I was unable to get this to work or find any details in the core.
See the commented out lines in afterSurveyComplete() - be great to get this working.

Help as ever appreciated.

Mat.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
1 year 2 months ago - 1 year 2 months ago #142487 by DenisChenu
DenisChenu replied the topic: Webhook Plugin - a bit of assistance needed.
:kiss: seems really great !

Thank you .

For logging, i don't remind of the manual ? Maybe you can put the link ?
For my plugins, i use only my own log : github.com/SondagesPro/LS-sendMailCron#logging
I'm unsure for the 'application.plugins.pluginName', github.com/SondagesPro/LS-sendMailCron/b...endMailCron.php#L392 but think this way : admin user can really log what he want :) (see www.yiiframework.com/doc/guide/1.1/en/topics.logging for more details).

For url control : maybe we need a new setting type 'email' : github.com/mrcandu/limesurvey-webhook/bl...ster/WebHook.php#L49 . But i'm unsure we don't rewrite all of this part this year. Your system seems really great.

About {TOKEN}/{SURVEYID} etc ... i think you can use same function from LimeSurvey oif needed : this allow to use all Expression Manager var. For example if you have a question TYPE, you can use type={TYPE.NAOK}
See github.com/LimeSurvey/LimeSurvey/blob/ma...ntimeHelper.php#L720 or github.com/SondagesPro/LS-sendPdfReport/...ndPdfReport.php#L272 . BUT : all this part is not in API, we can use it but maybe in future this function don't exist .

Again : thanks you :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 1 year 2 months ago by DenisChenu.

Please Log in to join the conversation.

More
1 year 2 months ago - 1 year 2 months ago #142553 by web_digital
web_digital replied the topic: Webhook Plugin - a bit of assistance needed.
Hi Denis

Thanks for the feedback - going to have a look at improving things a bit later today.

Regarding the logging - the bit in the manual that I was referring to is here:
manual.limesurvey.org/Plugins
It suggests the Plugin object has a method of "log" which is not the case.
Thanks for your example logging code - I have tried using this - which should work, but I'm not getting any log files written to the server at present. I have checked permissions etc. Will investigate later and post some code.

Regarding using the Expression Manager - that seems like a good plan - I was hoping it might be possible to parse the parameters using a built function. :) Will investigate further!

Thanks

Mat.
Last Edit: 1 year 2 months ago by web_digital. Reason: Typo

Please Log in to join the conversation.

More
1 year 2 months ago #142579 by olle
olle replied the topic: Webhook Plugin - a bit of assistance needed.
Sorry, that's my fault. The logging is still part of a branch that hasn't been merged. The same goes for translations. I will update the docs.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
1 year 2 months ago #142580 by DenisChenu
DenisChenu replied the topic: Webhook Plugin - a bit of assistance needed.

web_digital wrote: I have tried using this - which should work, but I'm not getting any log files written to the server at present. I have checked permissions etc. Will investigate later and post some code.....


For testing : did you add something here github.com/mrcandu/limesurvey-webhook/bl...ster/WebHook.php#L73

For example
Yii::log("afterSurveyComplete", 'trace','application.plugins.WebHook');
?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 year 2 months ago #142637 by web_digital
web_digital replied the topic: Webhook Plugin - a bit of assistance needed.
Tried adding that line in Denis, but no luck:
github.com/mrcandu/limesurvey-webhook/bl...ster/WebHook.php#L77

I'm expecting to see some logs in the tmp folder, but I have searched the rest of the directory and there is nothing.
I have tried writing files in PHP to this location and that works fine.
Running 2.53+161004

Will have look in the code and see if I can work out whats going on.
Thanks.

Please Log in to join the conversation.

More
1 year 2 months ago #142654 by DenisChenu
DenisChenu replied the topic: Webhook Plugin - a bit of assistance needed.

web_digital wrote: I'm expecting to see some logs in the tmp folder, but I have searched the rest of the directory and there is nothing.

From me it's in tmp/runtime directory by default. I have some issue when try different directory/fila name, then before track down what happen : i leave default from LS.

Else (just for testing) : tracevar function work (if you set config=2).

I check quickly what i have with your plugin.

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!