This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (pokemon_endpoint.indexOf(specs) !== -1) { | |
| const { data } = await axios_instance.get(`/pokemon/${pokemon}`); | |
| let fulfillmentText; | |
| const id = String(data.id).padStart(3, '0'); | |
| const value = (specs == 'abilities') ? data.abilities.map(item => item.ability.name).join(', ') : data.moves.map(item => item.move.name).join(', '); | |
| fulfillmentText = `The ${specs} of ${pokemon} are: ${value}`; | |
| Object.assign(response_obj, { fulfillmentText }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { intent, parameters, outputContexts, queryText } = req.body.queryResult; | |
| const pokemon = (parameters.pokemon) ? parameters.pokemon.toLowerCase().replace('.', '-').replace(' ', '').replace("'", "") : ''; | |
| const specs = parameters.specs; | |
| const get_type_effectiveness = (parameters.type_effectiveness) ? true : false; | |
| let response_obj = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const pokemon_endpoint = ['abilities', 'moves', 'photo']; | |
| const pokemon_species_endpoint = ['description', 'evolution']; | |
| app.post("/pokedex", async (req, res) => { | |
| try { | |
| const { intent, parameters, outputContexts, queryText } = req.body.queryResult; | |
| const pokemon = (parameters.pokemon) ? parameters.pokemon.toLowerCase().replace('.', '-').replace(' ', '').replace("'", "") : ''; | |
| const specs = parameters.specs; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require("express"); | |
| const bodyParser = require("body-parser"); | |
| const cors = require("cors"); | |
| const axios = require("axios"); | |
| require("dotenv").config(); | |
| const app = express(); | |
| app.use(bodyParser.urlencoded({ extended: true })); | |
| app.use(bodyParser.json()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| showResponse(text, payload) { | |
| let msg = { | |
| _id: this.state.messages.length + 1, | |
| text, | |
| createdAt: new Date(), | |
| user: BOT_USER | |
| }; | |
| if (payload && payload.is_image) { | |
| msg.text = text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| handleResponse(result) { | |
| console.log(result); | |
| let text = result.queryResult.fulfillmentMessages[0].text.text[0]; | |
| let payload = result.queryResult.webhookPayload; | |
| this.showResponse(text, payload); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| onSend(messages = []) { | |
| this.setState(previousState => ({ | |
| messages: GiftedChat.append(previousState.messages, messages) | |
| })); | |
| let message = messages[0].text; | |
| Dialogflow_V2.requestQuery( | |
| message, | |
| result => this.handleResponse(result), | |
| error => console.log(error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| render() { | |
| return ( | |
| <View style={styles.container}> | |
| <GiftedChat | |
| messages={this.state.messages} | |
| onSend={messages => this.onSend(messages)} | |
| user={{ | |
| _id: 1 | |
| }} | |
| /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| componentDidMount() { | |
| Dialogflow_V2.setConfiguration( | |
| dialogflowConfig.client_email, | |
| dialogflowConfig.private_key, | |
| Dialogflow_V2.LANG_ENGLISH_US, | |
| dialogflowConfig.project_id | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const BOT_USER = { | |
| _id: 2, | |
| name: 'Poke Bot', | |
| avatar: 'https://ui-avatars.com/api/?background=0D8ABC&color=fff&name=Poke Bot' | |
| }; | |
| class App extends Component { | |
| state = { | |
| messages: [ | |
| { |