Skip to content

Commit

Permalink
feat: add chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
geeekgod committed Apr 14, 2023
1 parent 71ccfc8 commit 821a75f
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'

const bloodLineApi = axios.create({
baseURL: 'https://bloodline-api.middleware-api.ml/api',
baseURL: 'https://api.thisisrishabh-azure.ml/api',
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Headers": "Authorization",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CustomDrawerHeader from '../../components/CustomDrawerHeader';
import SavedRequests from '../../screens/SavedRequests';
import NearByRequests from '../../screens/NearByRequests';
import MapRequestsView from '../../screens/MapRequestsView';
import ChatBot from '../../screens/ChatBot';

const Drawer = createDrawerNavigator();

Expand Down Expand Up @@ -83,6 +84,15 @@ const DrawerNavigator = () => {
),
}}
component={PostRequest} />
<Drawer.Screen name="ChatBot"
options={{
header: (props) => <CustomDrawerHeader {...props} title={'Chat Bot'} />,
drawerLabel: "Chat Bot",
drawerIcon: ({ color }) => (
<Ionicons name="chatbubbles-sharp" size={25} color={color} />
),
}}
component={ChatBot} />
</Drawer.Navigator>
);
}
Expand Down
62 changes: 62 additions & 0 deletions app/screens/ChatBot/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { useState, useCallback, useContext } from 'react'
import { GiftedChat } from 'react-native-gifted-chat'
import bloodLineApi from '../../api';
import { AuthContext } from '../../context/AuthContext';

const ChatBot = () => {

const {user} = useContext(AuthContext);

const [messages, setMessages] = useState([]);

const sendMessage = useCallback(async (message) => {
bloodLineApi.post('/chatbot', { query: message }).then((res) => {
console.log("Response from chatbot", res.data.response);
setMessages(previousMessages => GiftedChat.append(
previousMessages,
{
_id: previousMessages.length + 1,
text: res.data.response,
createdAt: new Date(),
user: {
_id: 2,
name: 'Blood Line',
avatar: require('../../assets/logo.png'),
}
}
))
}).catch((err) => {
console.log("Error while sending message", err);
})
}, [])


const onSend = useCallback(async (messages = []) => {
setMessages(previousMessages => GiftedChat.append(previousMessages, {
_id: previousMessages.length + 1,
text: messages[0].text,
createdAt: new Date(),
user: {
_id: 1,
name: user.name,
avatar: user.imageUrl,
}
}))
await sendMessage(messages[0].text)
}, [])

return (
<GiftedChat
messages={messages}
showUserAvatar={true}
showAvatarForEveryMessage={true}
placeholder='Enter your query here...'
onSend={messages => onSend(messages)}
user={{
_id: 1,
}}
/>
)
}

export default ChatBot;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"react-native-dynamic-search-bar": "WrathChaos/react-native-dynamic-search-bar#expo",
"react-native-dynamic-vector-icons": "WrathChaos/react-native-dynamic-vector-icons#expo",
"react-native-gesture-handler": "~2.5.0",
"react-native-gifted-chat": "^2.0.1",
"react-native-maps": "^1.4.0",
"react-native-reanimated": "~2.9.1",
"react-native-safe-area-context": "4.3.1",
Expand Down
100 changes: 96 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,14 @@
semver "7.3.2"
xml2js "0.4.23"

"@expo/[email protected]":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@expo/react-native-action-sheet/-/react-native-action-sheet-4.0.1.tgz#fa78e55a87a741f235be2c4ce0b0ea2b6afd06cf"
integrity sha512-FwCFpjpB6yzrK8CIWssLlh/i6zQFytFBiJfNdz0mJ2ckU4hWk8SrjB37P0Q4kF7w0bnIdYzPgRbdPR9hnfFqPw==
dependencies:
"@types/hoist-non-react-statics" "^3.3.1"
hoist-non-react-statics "^3.3.0"

"@expo/[email protected]":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@expo/rudder-sdk-node/-/rudder-sdk-node-1.1.1.tgz#6aa575f346833eb6290282118766d4919c808c6a"
Expand Down Expand Up @@ -2742,6 +2750,14 @@
resolved "https://registry.yarnpkg.com/@types/hammerjs/-/hammerjs-2.0.41.tgz#f6ecf57d1b12d2befcce00e928a6a097c22980aa"
integrity sha512-ewXv/ceBaJprikMcxCmWU1FKyMAQ2X7a9Gtmzw8fcg2kIePI1crERDM818W+XYrxqdBBOdlf2rm137bU+BltCA==

"@types/hoist-non-react-statics@^3.3.1":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
dependencies:
"@types/react" "*"
hoist-non-react-statics "^3.3.0"

"@types/invariant@^2.2.35":
version "2.2.35"
resolved "https://registry.yarnpkg.com/@types/invariant/-/invariant-2.2.35.tgz#cd3ebf581a6557452735688d8daba6cf0bd5a3be"
Expand Down Expand Up @@ -2788,11 +2804,30 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/prop-types@*":
version "15.7.5"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==

"@types/qs@^6.5.3":
version "6.9.7"
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb"
integrity sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==

"@types/react@*":
version "18.0.35"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.35.tgz#192061cb1044fe01f2d3a94272cd35dd50502741"
integrity sha512-6Laome31HpetaIUGFWl1VQ3mdSImwxtFZ39rh059a1MNnKGqBpC88J6NJ8n/Is3Qx7CefDGLgf/KhN/sYCf7ag==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.16.3"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.3.tgz#cef09e3ec9af1d63d2a6cc5b383a737e24e6dcf5"
integrity sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==

"@types/use-subscription@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/use-subscription/-/use-subscription-1.0.0.tgz#d146f8d834f70f50d48bd8246a481d096f11db19"
Expand Down Expand Up @@ -3806,6 +3841,11 @@ dag-map@~1.0.0:
resolved "https://registry.yarnpkg.com/dag-map/-/dag-map-1.0.2.tgz#e8379f041000ed561fc515475c1ed2c85eece8d7"
integrity sha512-+LSAiGFwQ9dRnRdOeaj7g47ZFJcOUPukAP8J3A3fuZ1g9Y44BG+P1sgApjLXTQPOzC4+7S9Wr8kXsfpINM4jpw==

[email protected]:
version "1.8.26"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.26.tgz#c6d62ccdf058ca72a8d14bb93a23501058db9f1e"
integrity sha512-KqtAuIfdNfZR5sJY1Dixr2Is4ZvcCqhb0dZpCOt5dGEFiMzoIbjkTSzUb4QKTCsP+WNpGwUjAFIZrnZvUxxkhw==

dayjs@^1.8.15:
version "1.11.5"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.5.tgz#00e8cc627f231f9499c19b38af49f56dc0ac5e93"
Expand Down Expand Up @@ -6729,7 +6769,16 @@ prompts@^2.3.2, prompts@^2.4.0:
kleur "^3.0.3"
sisteransi "^1.0.5"

prop-types@^15.6.2, prop-types@^15.7.2:
[email protected]:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
dependencies:
loose-envify "^1.4.0"
object-assign "^4.1.1"
react-is "^16.8.1"

prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.7.x:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
Expand Down Expand Up @@ -6840,7 +6889,7 @@ react-freeze@^1.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==

react-is@^16.13.0, react-is@^16.13.1, react-is@^16.7.0:
react-is@^16.13.0, react-is@^16.13.1, react-is@^16.7.0, react-is@^16.8.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
Expand All @@ -6865,6 +6914,11 @@ react-native-codegen@^0.69.2:
jscodeshift "^0.13.1"
nullthrows "^1.1.1"

[email protected]:
version "2.2.1"
resolved "https://registry.yarnpkg.com/react-native-communications/-/react-native-communications-2.2.1.tgz#7883b56b20a002eeb790c113f8616ea8692ca795"
integrity sha512-5+C0X9mopI0+qxyQHzOPEi5v5rxNBQjxydPPiKMQSlX1RBIcJ8uTcqUPssQ9Mo8p6c1IKIWJUSqCj4jAmD0qVQ==

react-native-dynamic-search-bar@WrathChaos/react-native-dynamic-search-bar#expo:
version "2.0.2"
resolved "https://codeload.github.com/WrathChaos/react-native-dynamic-search-bar/tar.gz/91f5aeeec42fb4f9cf0a41d5e1dcd17dd0f1968d"
Expand All @@ -6884,12 +6938,28 @@ react-native-gesture-handler@~2.5.0:
lodash "^4.17.21"
prop-types "^15.7.2"

react-native-gifted-chat@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/react-native-gifted-chat/-/react-native-gifted-chat-2.0.1.tgz#6d7cc7a8cb884a53bff608dcb6a0becc690d9a34"
integrity sha512-3cXMmKp4tJ7sbWEz9wKFV3coELkfI8RsK0ZC/hR9S6vJlHyCLwTK0r3UaOX1/aXP3PLG9uvjygpzFe3qeeUUmw==
dependencies:
"@expo/react-native-action-sheet" "4.0.1"
dayjs "1.8.26"
prop-types "15.7.2"
react-native-communications "2.2.1"
react-native-iphone-x-helper "1.3.1"
react-native-lightbox-v2 "0.9.0"
react-native-parsed-text "0.0.22"
react-native-typing-animation "0.1.7"
use-memo-one "1.1.2"
uuid "3.4.0"

react-native-gradle-plugin@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/react-native-gradle-plugin/-/react-native-gradle-plugin-0.0.7.tgz#96602f909745239deab7b589443f14fce5da2056"
integrity sha512-+4JpbIx42zGTONhBTIXSyfyHICHC29VTvhkkoUOJAh/XHPEixpuBduYgf6Y4y9wsN1ARlQhBBoptTvXvAFQf5g==

react-native-iphone-x-helper@^1.0.3:
react-native-iphone-x-helper@1.3.1, react-native-iphone-x-helper@^1.0.3:
version "1.3.1"
resolved "https://registry.yarnpkg.com/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.3.1.tgz#20c603e9a0e765fd6f97396638bdeb0e5a60b010"
integrity sha512-HOf0jzRnq2/aFUcdCJ9w9JGzN3gdEg0zFE4FyYlp4jtidqU03D5X7ZegGKfT1EWteR0gPBGp9ye5T5FvSWi9Yg==
Expand All @@ -6902,13 +6972,25 @@ react-native-keyboard-aware-scroll-view@^0.9.5:
prop-types "^15.6.2"
react-native-iphone-x-helper "^1.0.3"

[email protected]:
version "0.9.0"
resolved "https://registry.yarnpkg.com/react-native-lightbox-v2/-/react-native-lightbox-v2-0.9.0.tgz#b97be4d892ebb959069c451948b11da390bc46d8"
integrity sha512-Fc5VFHFj2vokS+OegyTsANKb1CYoUlOtAv+EBH5wtpJn1b5cey6jVXH7136G5+8OC9JmKWSgKHc5thFwOoZTUg==

react-native-maps@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/react-native-maps/-/react-native-maps-1.4.0.tgz#e24133311c032447c35e55152841c4e0e9ddf2a5"
integrity sha512-asP6oVx9uF4E9U22j40q0AcSJ4v3hPBPCg1kPdlbckGXGj+z8dwwdPkQi3hUpl94odlR//v60Sw6PAEYv8zSxw==
dependencies:
"@types/geojson" "^7946.0.8"

[email protected]:
version "0.0.22"
resolved "https://registry.yarnpkg.com/react-native-parsed-text/-/react-native-parsed-text-0.0.22.tgz#a23c756eaa5d6724296814755085127f9072e5f5"
integrity sha512-hfD83RDXZf9Fvth3DowR7j65fMnlqM9PpxZBGWkzVcUTFtqe6/yPcIoIAgrJbKn6YmtzkivmhWE2MCE4JKBXrQ==
dependencies:
prop-types "^15.7.x"

react-native-reanimated@~2.9.1:
version "2.9.1"
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-2.9.1.tgz#d9a932e312c13c05b4f919e43ebbf76d996e0bc1"
Expand Down Expand Up @@ -6953,6 +7035,11 @@ [email protected]:
css-select "^4.2.1"
css-tree "^1.0.0-alpha.39"

[email protected]:
version "0.1.7"
resolved "https://registry.yarnpkg.com/react-native-typing-animation/-/react-native-typing-animation-0.1.7.tgz#8f2cf08d9400ae543a110292eb7d71523dda5528"
integrity sha512-4H3rF9M+I2yAZpYJcY0Mb29TXkn98QK12rrKSY6LZj1BQD9NNmRZuNXzwX4XHapsIz+N/J8M3p27FOQPbfzqeg==

[email protected]:
version "0.69.6"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.69.6.tgz#cdd1a5757d902b91b165c28fdda4e518ed6f683a"
Expand Down Expand Up @@ -8133,6 +8220,11 @@ use-latest-callback@^0.1.5:
resolved "https://registry.yarnpkg.com/use-latest-callback/-/use-latest-callback-0.1.5.tgz#a4a836c08fa72f6608730b5b8f4bbd9c57c04f51"
integrity sha512-HtHatS2U4/h32NlkhupDsPlrbiD27gSH5swBdtXbCAlc6pfOFzaj0FehW/FO12rx8j2Vy4/lJScCiJyM01E+bQ==

[email protected]:
version "1.1.2"
resolved "https://registry.yarnpkg.com/use-memo-one/-/use-memo-one-1.1.2.tgz#0c8203a329f76e040047a35a1197defe342fab20"
integrity sha512-u2qFKtxLsia/r8qG0ZKkbytbztzRb317XCkT7yP8wxL0tZ/CzK2G+WWie5vWvpyeP7+YoPIwbJoIHJ4Ba4k0oQ==

use-subscription@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/use-subscription/-/use-subscription-1.8.0.tgz#f118938c29d263c2bce12fc5585d3fe694d4dbce"
Expand Down Expand Up @@ -8160,7 +8252,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==

uuid@^3.3.2, uuid@^3.4.0:
uuid@3.4.0, uuid@^3.3.2, uuid@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
Expand Down

0 comments on commit 821a75f

Please sign in to comment.