🕹Creating HayWord Feature
this time we will create a HayWord feature by attracting users to guess the word based on definitions, synonyms, and word types.
#
Creating HayWord Menu With Generic Templates
Create a
menuPayload
variable for the menu template with Generic type.Show Details
tip
Find more Message template here
Add menu instructions when the user is done saving their profile.
Show Details
Displays the menu template from menuPayload when the user types
menu
in messenger in the handleMessage function.Show Details
#
Using the WordsAPINow we will use the API 'WordsAPI' in RapidAPI to translate the words that users input in the chat.
Go to WordsAPI RapidAPI page, make sure you are logged in.
Just like the steps for using Just Translated API, subscribe to the test > choose the basic plan.
Copy the sample code provided by RapidAPI, on the right, select the programming language Node.js > Request.
Show Details
Create a
getWord ()
function in the app.js file from the code previously copied to get the word the user will guess.Create the
var modeHayWord; var word; var def; var wordType; var synonym; var censored; var featureHayWord = [];
globally.Show Details
info
We need to make it globally because the variables will be accessed by different function and use it as a state.
Create a
PLAY_HAYWORD
postback response to the handlePostback() function to call the getWord() function.
#
Provide Hints and Check User Answersnow we will provide the hint to the user and check the user's answer whether it is right or wrong.
Updated the handleMessage() function to add hint responses and answer results.