DaveMoTron
DaveMoTron

Reputation: 23

Looking for a way to pass Typeform results text back from a FB Messenger WebView into the chat

I am creating a chatbot using Dialogflow in FB Messenger that links people out to Typeform quizzes using Webview UI. So they select a quiz in a Messenger chat, and it opens the Typeform in a window, and then complete the quiz. I would like to get the text from the Typeform results screen and inject it back into Messenger so the user can see a history of their results.

I have been searching for a way to do this but my google-fu has proved weak.

Upvotes: 1

Views: 444

Answers (1)

MichaelSolati
MichaelSolati

Reputation: 2872

So you wouldn't be able to get the result of the form submission from the webview, in fact if you're just using the webview and displaying the Typeform url you wont necessarily know when the user submits.

I think the first thing I'd suggest is hosting the form on a webpage and use either the Embed SDK or Typeform Elements. The main reason why is because both provide an onsubmit lifecycle that you can at least know when the user submits the form and then act upon that. There's more to this, but I'll come back to this soon...

The next thing you'll want/need to do is to be able to act upon a user submitting a form. You can do that by querying submissions with the Typeform API (which you'll know when to call/use because the previous step will inform you the user has submitted the form thanks to the onsubmit callback), or have a server where you listen for a webhook which we will fire on submission.

So the next step/concern is knowing how to query a user's unique submission. The way I'd recommend this is via an unique hidden field in the form URL that you can query or validate in the previous paragraph. If you're using Dialogflow you can probably have the intent that directs the user to form in the webview call a webhook you create (firebase?) to then create a unique id for that sessions that you'd store in a database, use that uid as a hidden field in the form you send to facebook messenger, and then you can use that uid as an identifier when you query via the SDK or when you're listening via webhooks.

Upvotes: 4

Related Questions