Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi
  • Page :
  • 1
  • 2

SUJET : Automated / Web Service Based Token Generation

Automated / Web Service Based Token Generation il y a 3 ans 1 jour #65695

  • brian
  • Portrait de brian
  • Hors ligne
  • Fresh Lemon
  • Messages : 6
  • Karma: 0
Hello friends -

This looks like a really neat tool! I am very impressed with my basic playing around with it. That being said, I'm wondering if anyone has crafted a solution to my problem.

I have a need to periodically (daily) generate tokens in an automated fashion. I'm may need to send out my emails with tokens from a source other than lime for a variety of valid and otherwise imposed reasons. What I can't do is manually load a .csv up every day that defines the recipients I'd like to toggle with a request to take a survey. The idea is that as another system generates specific pieces of data (customer X had work Y performed at location Z), and I'd like to toggle that customer on taking a survey. The volume is up and down, but most importantly, happens throughout the day and week and I need notifications to go out without me doing anything manually.

That being said, it looks like I need guidance on a few things:

1) Creating tokens in an automated fashion. I'm competent enough on the jdbc end to write inserts into lime_tokens_##### if necessary, but thought there might be capacities within the tool that would allow me to bypass this step. I'd also love the have the tool generate the token hash instead of providing one on my end, though I could make one up.

2) Automate notifications to token holders that haven't gotten emailed yet. Is there any way to handle this from a data level? Would a HTTP POST to a php page make this work? I'm new to PHP, could could generate a GET or POST from java to make it happen.

Any insight would be greatly appreciated.

brian
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Automated / Web Service Based Token Generation il y a 3 ans 1 jour #65697

  • timbee
  • Portrait de timbee
  • Hors ligne
  • Junior Lime
  • Messages : 20
  • Remerciements reçus 1
  • Karma: 1
to your first point, how do you expect limesurvey to handle automatic creation of tokens when it doesn't know when they should be updated?

I'm in a similar situation right now. We have our own web application that has a customer table. When we make updates to the customer record (let's say we have to change their name that had a typo) the application makes an additional call to the lime_tokens_# table. Hypothetically speaking that is :) still implementing. I think the trick also is to make our web app aware of which lime survey # (and thus lime_tokens_#) should be linked with our customer data.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Automated / Web Service Based Token Generation il y a 3 ans 1 jour #65698

  • brian
  • Portrait de brian
  • Hors ligne
  • Fresh Lemon
  • Messages : 6
  • Karma: 0
Hi Timbee -

Well, I'd be willing to make a call, http get / post from java land to the appropriate .php page to create the tokens if I have to. My problem is that I don't know much about php, I was hoping there was a cleaner solution besides psuedo-crawling into the application to simulate someone clicking on a button. And as I think about this some more, I can make a hash tag just as easily at insert time.

Similarly with initiating the email to un-notified parties; I can handle that externally if necessary, but would rather leverage what is already there. It just seems like the last step is missing (or I am missing it), namely, a way to make the functions fire without actually being there.

brian
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Automated / Web Service Based Token Generation il y a 2 ans 11 mois #65847

  • Mazi
  • Portrait de Mazi
  • Hors ligne
  • LimeSurvey Team
  • Messages : 5325
  • Remerciements reçus 296
  • Karma: 249
@1: When do you want to create tokens? Which event should trigger the creation of the tokens and the insert of token data like First name, last name and email (which are the required fields)?

@2: The easiest way for automatically sending invitations/reminders is to create a cronjob which is run daily and pics the according users which meet certain criteria (survey not filled out yet, no invitation/reminder sent yet, email address exists, ...). These will then receive an invitation/reminder automatically.

For issue #1 a cronjob might also do the trick. Simply connect a customized PHP script to your DB and read out all user which were added today and then add them to the token table of a predefined survey (it could also send the invitation right away).

As I see it there are no inbuild feature whcih could help you out. Some custom coding is needed anyway to connect the systems and automate certain processes.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Automated / Web Service Based Token Generation il y a 2 ans 11 mois #65971

  • timbee
  • Portrait de timbee
  • Hors ligne
  • Junior Lime
  • Messages : 20
  • Remerciements reçus 1
  • Karma: 1
brian écrit:
I'd be willing to make a call, http get / post from java land to the appropriate .php page to create the tokens if I have to. My problem is that I don't know much about php,

You don't really need to make any php-originated http calls. As long as your java has access to the same database, all you should have to keep track of is which unique token id is associated to which unique user id on your system. So let's say you have a survey (lime_survey_353), and you initially enable tokens, so it creates the lime_tokens_353 table. Ten minutes later your java program gets a request to initiate a survey for user_id 21, so all the java app has to do is an SQL insert statement on the lime_tokens_353 table. Generate a random token yourself, and then in your java user table make sure that user_id 21 also has a token_id field so you can link the two. Then as Mazi suggests, use a cron job to send mail out every 5 minutes or something like that.

What sucks about this is that there is a separate token table for each survey that you have to keep track of. This was resolved with the "central participants database" in version 2, but we're sticking with the 1.9x branch for stability. Not sure how tested the CI version is...
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Automated / Web Service Based Token Generation il y a 2 ans 11 mois #66042

  • Mazi
  • Portrait de Mazi
  • Hors ligne
  • LimeSurvey Team
  • Messages : 5325
  • Remerciements reçus 296
  • Karma: 249
timbee écrit:
What sucks about this is that there is a separate token table for each survey that you have to keep track of. This was resolved with the "central participants database" in version 2, but we're sticking with the 1.9x branch for stability. Not sure how tested the CI version is...
You have just volunteered to test and report bugs: www.limesurvey.org/en/component/content/...is-ready-for-testing

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
L'administrateur a désactivé l'accès en écriture pour le public.
Cet utilisateur a été remercié pour son message par: timbee

Re: Automated / Web Service Based Token Generation il y a 2 ans 11 mois #66062

  • timbee
  • Portrait de timbee
  • Hors ligne
  • Junior Lime
  • Messages : 20
  • Remerciements reçus 1
  • Karma: 1
Mazi écrit:
You have just volunteered to test and report bugs: www.limesurvey.org/en/component/content/...is-ready-for-testing

Lol, I like your style Mazi. Well, I can tell you it install's fine, haha. We have too much going on right now for a thorough testing ... I am interested in digging under the hood of the new CI architecture though, maybe on my personal time.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Automated / Web Service Based Token Generation il y a 2 ans 11 mois #66068

  • Mazi
  • Portrait de Mazi
  • Hors ligne
  • LimeSurvey Team
  • Messages : 5325
  • Remerciements reçus 296
  • Karma: 249
timbee écrit:
Mazi écrit:
You have just volunteered to test and report bugs: www.limesurvey.org/en/component/content/...is-ready-for-testing

Lol, I like your style Mazi. Well, I can tell you it install's fine, haha. We have too much going on right now for a thorough testing ... I am interested in digging under the hood of the new CI architecture though, maybe on my personal time.
That would be great. We really need some help testing new features. There are probably quite a few bugs. You'll get a cookie for each ticket you create ;-)

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Automated / Web Service Based Token Generation il y a 1 an 10 mois #87147

  • michaeljean
  • Portrait de michaeljean
  • Hors ligne
  • Fresh Lemon
  • Messages : 3
  • Karma: 0
Hi all,

I had a similar problem. I wanted to automatically register users for a second survey once they finished the first one. Here is the script I used to solve it. Change all the stuff that looks like <this> with your stuff. Doing it this way means that the invitation is sent automatically once the users are registered.

export-users.php:
<?php
/*
 * Gets survey participants that have completed survey 1 and automatically registers them for survey 2.
 * Also saves a CSV file called "export-users.csv" on the web host in the survey application folder.
 * This file can be used to manually import the user tokens in case something goes wrong with the 
 * automation.
 */
 
/*
 *
 * Set the database objects
 *
 */
/* Database name */
$db_name = '<my_db_name>';
 
/* Database username */
$db_user = '<my_db_user>';
 
/* Database password */
$db_password = '<my_db_password>';
 
/* Database hostname */
$db_host = '<my_db_host>';
 
$table_name_survey_1_tokens = "lime_tokens_<my_survey_id>"; /* Database survey 1 user tokens table name */
 
/* Database where clause to get users who have completed survey 1 and their closing date is past */
$where_clause = " where date(a.completed) < now()";
 
$field_list = "a.tid,a.firstname,a.lastname,a.email,a.emailstatus,a.token,a.language"; /* The field list as text. */
 
$field_list_array = explode(',',str_replace('a.', '', $field_list) ); /* Field list as an array; required by the fputcsv function. */
 
$csv_filename = 'export-users.csv'; /* Output CSV filename */
 
 
/***** Start of processing *****/
 
/*
 *
 * Establish database connection
 *
 */
$conn = mysql_connect($db_host, $db_user, $db_password) or die(mysql_error());
mysql_select_db($db_name, $conn) or die(nl2br(mysql_error($conn) . "\n"));
echo nl2br("Established database connection.\n");
 
 
/*
 *
 * Execute SQL query to find survey users that have completed survey 1
 *
 */
$query = "SELECT " . $field_list . " FROM " . $table_name_survey_1_tokens . " as a" . $where_clause;
$result = mysql_query($query, $conn) or die(mysql_error($conn));
echo nl2br("Found survey users that have completed survey 1.\n");
 
 
/*
 *
 * Output data rows (if atleast one row exists)
 *
 */
$row = mysql_fetch_assoc($result);
$fp = fopen($csv_filename, 'w');
fputcsv($fp,$field_list_array);
while ($row) {
    fputcsv($fp,$row,',','"');
    register($row[firstname],$row[lastname],$row[email]);
    echo nl2br("User " . $row['firstname'] . " " . $row['lastname'] . " at " . $row['email'] . " was registered.\n");
    $row = mysql_fetch_assoc($result);
}
fclose($fp);
echo nl2br("CSV file export-users.csv created.");
 
 
/*
 *
 * Function to register users.
 *
 */
function register($firstname,$lastname,$email)
{
 
$data = array(
    'lang' => 'en',
    'sid' => '<my_survey_id>',
    'register_firstname' => $firstname,
    'register_lastname' => $lastname,
    'register_email' => $email 
);
 
$post_str = '';
foreach($data as $key=>$val) {
    $post_str .= $key.'='.urlencode($val).'&';
}
$post_str = substr($post_str, 0, -1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '<my_URL>/index.php/register/index/sid/<my_survey_id>' );
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
 
}
 
 
?>
Dernière édition: il y a 1 an 10 mois par michaeljean.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Automated / Web Service Based Token Generation il y a 1 an 9 mois #89397

  • Mazi
  • Portrait de Mazi
  • Hors ligne
  • LimeSurvey Team
  • Messages : 5325
  • Remerciements reçus 296
  • Karma: 249
Instead of reading data from a CSV file, why don't you just modify the script and call it at the end of survey 1 to automatically create a new token for the current user at survey 2 and then automatically redirect him to that survey and attaching the generated token so they can start with survey 2 right away?

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
L'administrateur a désactivé l'accès en écriture pour le public.
  • Page :
  • 1
  • 2
Modérateurs: ITEd
Temps de génération de la page : 0.229 secondes
Donation Image