Skip to main content
Question

Request for Help: Debugging Typeform Quiz Integration with Zapier and ChatGPT

  • 4 June 2024
  • 0 replies
  • 10 views

 

Background:

I am working on a project to create a dynamic quiz using Typeform, with questions generated from a transcript using the ChatGPT API. The goal is to generate multiple-choice questions, track the user's score, and display the final score on the thank you screen. The integration process involves using Zapier to handle the data flow and logic between ChatGPT and Typeform.

Process Overview:

  1. ChatGPT API Prompt: The following prompt is used to instruct ChatGPT to generate the quiz questions:

     
    plaintext

    Copy code

    You are an expert quiz creator specializing in creating multiple-choice questions in a Typeform-compatible JSON format from transcripts. Your task is to analyze the following transcript and generate quiz content, including a name field and precisely 10 challenging multiple-choice questions in English. Transcript: {{240955785__transcript}} Guidelines: - Name Field: Include a "short_text" field with the "ref" value set to "name_field" and mark it as required. This field should be the first item in the JSON array. - Questions: Create 10 multiple-choice questions, each with a clear and concise "title" and a unique "ref" value (e.g., "question_1", "question_2", etc.). The "ref" values should be in the format "question_nnumber]" (e.g., "question_1", "question_2", etc.). - Answer Options: Provide 4 plausible answer options for each question within the "choices" array. Mark the correct answer with "ref": "correct" and the incorrect answers with "ref": "incorrect1", "incorrect2", and "incorrect3". Ensure that the correct answer is not always in the same position and varies randomly. - Difficulty: Craft questions that require a deep understanding of the transcript's content. Output Format: Output ONLY the valid JSON array containing the specified structure for the name field and each question. Do NOT include any additional text, explanations, or formatting characters. Example Question Object: { "type": "multiple_choice", "title": "What is the most common material used for dental implants?", "ref": "question_1", "properties": { "choices": : { "label": "Gold", "ref": "incorrect1" }, { "label": "Titanium", "ref": "correct" }, { "label": "Silver", "ref": "incorrect2" }, { "label": "Ceramic", "ref": "incorrect3" } ], "randomize": false, "allow_other_choice": false }, "validations": { "required": true } } Output exactly 10 question objects in the specified JSON format. Include only the JSON array in your response.

  2. Zapier Code: The following code in Zapier processes the ChatGPT output, generates the Typeform fields, and creates scoring logic for tracking the user's score:

     
    javascript

    Copy code

    const chatGPToutput = inputDataa'Conversation in ChatGPT']; let typeformFields = ]; let scoringLogic = ]; try { typeformFields = JSON.parse(chatGPToutput); // Extract question references (excluding the name field) const questionRefs = typeformFields .filter(field => field.type === 'multiple_choice') .map(field => field.ref); // Generate scoring logic for each question scoringLogic = questionRefs.map(ref => ({ type: 'field', ref: ref, actions: s { action: 'add', details: { target: { type: 'variable', value: 'score' }, value: { type: 'constant', value: 1 } }, condition: { op: 'is', vars: s { type: 'field', value: ref }, { type: 'choice', value: typeformFields.find(field => field.ref === ref).properties.choices.find(choice => choice.ref === 'correct').ref } ] } } ] })); } catch (error) { console.error("Error parsing JSON from ChatGPT:", error); } return { typeformFields: JSON.stringify(typeformFields), scoringLogic: JSON.stringify(scoringLogic), scoreVariable: '{{score}}' };

  3. Typeform API Request: The API request in Typeform uses the fields and logic generated by the Zapier code to create the quiz and attempts to display the final score on the thank you screen:

     
    json

    Copy code

    { "title": "Quiz from Transcript", "variables": { "score": 0 }, "theme": { "href": "https://api.typeform.com/themes/dBADdiNW" }, "fields": {{241267617__typeformFields}}, "logic": {{241267617__scoringLogic}}, "thankyou_screens": s { "title": "Thank you!\nYour Final Score is\n{{241267617__scoreVariable}}", "properties": { "show_button": true, "button_text": "Create a typeform", "button_mode": "default_redirect", "share_icons": true } } ] }

Problem:

  • The score variable does not transfer the data correctly from the previous steps into the API request in Typeform.
  • Despite setting up the scoring logic, the final score is not displayed correctly on the thank you screen.

Challenge:

  • Ensure the score variable correctly passes the data from Zapier to Typeform and displays it accurately.
  • Explore alternative methods to recall the score and display it on the thank you screen.

Final Goal:

  • Successfully display the user's final score on the thank you screen after completing the quiz.

Request for Help:

  • I need guidance on debugging this issue and finding a solution to correctly display the score using the current setup.
  • Any insights or suggestions on how to improve the data transfer between Zapier and Typeform or alternative methods to achieve the desired result would be greatly appreciated.

0 replies

Be the first to reply!

Reply