Creating Roblox Basic Chatbot
Hey everyone, in this tutorial I am going to show you how to make your own Chatbot using google’s newly released bard.
Heres the preview of the end result.
We will be using repl.it as our backend cloud.
Creating the project
First head over to https://replit.com/ and create a account, once created
click on
Or directly click on this link, then this window will appear.
( We will be using python as our backend )
Once you decide the name and everything, click on create repl button.
Configuring backend
Now once our project is created, head over to your project terminal/shell.
There is no shell tab..
Now install the following packages
pip install bardapi
pip install flask
once they are installed, click on button and name the file index.py
and then type the following code:
import os
from bardapi import BardCookies
from flask import Flask, request, jsonify
app = Flask(__name__)
cookies = {
"__Secure-1PSID": os.environ['PSID'],
"__Secure-1PSIDTS": os.environ['PSIDTS'],
"__Secure-1PSIDCC": os.environ['PSIDCC']
}
print('starting..')
bard = BardCookies(cookie_dict=cookies)
@app.route('/', methods=['GET'])
def home():
if "txt" in request.args:
txt = request.args['txt']
response = ""
try:
response = bard.get_answer(txt)['content']
except:
return jsonify({"status": "ERROR", "text": "Invalid cookies"})
return jsonify({"status": "OK", "text": response})
else:
return jsonify({"status": "OK", "text": ""})
app.run(debug=False,port=3000,host="0.0.0.0")
Perfect! now lets head towards the next step.
Env and Cookies
Now head towards https://bard.google.com/ and login with your google account.
Then press F12 or Ctrl + Shift + I
Then click Application > Cookies > https://bard.google.com
From there we need these three cookies:
then copy their values
(NOTE: Dont share these cookies with anyone, these cookies contains sensitive information such as Session Token, Password, Account Info etc…)
Once you get their values put them in JSON likes so:
{
"PSIDTS": "sidts-XXXXXXXXXXXXXX-XXXXXX",
"PSID": "XXXXXXXXXX-XXXXXXXXXXX",
"PSIDCC": "XXXXXX-XXXXXX"
}
Put __Secure-1PSIDTS cookie value in PSIDTS
Put __Secure-1PSID cookie value in PSID
Put __Secure-1PSIDCC cookie value in PSIDCC
then copy the json, once done head over to your replit project and click Secrets.
Then this tab will open
Click on Edit as JSON then paste the thing youve copied and click save.
Once you click save it will look something like this:
and thats it! youre back end configured, click the run button to start your project
The webview tab will appear as soon as the project start running.
It will look something like this:
copy this url
(The url will be different on your side).
Implementing backend to our roblox game
First make sure http requests is enabled.
Game Settings > Security > Allow Http Request
Create a script in ServerScriptService, and type the following code:
local http = game:GetService("HttpService")
local remote = replicatedStorage:WaitForChild("RemoteFunction")
local chat = game:GetService("Chat")
local url = "YOUR_PROJECT_URL"
local query = "Hello, how are you!?"
local function filterText(plr:Player,txt:string)
return chat:FilterStringForBroadcast(txt,plr)
end
local newUrl = `{url}?txt={query}`
local res = http:GetAsync(newUrl)
local decoded = http:JSONDecode(res)
if decoded.status == "OK" then
local filtered = filterText(plr,decoded.text)
if not filtered then return end
print(filtered) -- I am doing good, what about you?
end
Run the game and boom! you got chatbot working.
Pros and Cons
Heres are some pros and cons
Pros
+ Uses google's data
+ Fast
+ Accurate
... etc
Cons
- Cookies will reset once in a while, so you have to do the setting cookies process again
- Long results which may get filtered if used in game.
(Keep in mind, brad is still in development so things might change in future).
If you think this post is helpful then you can donate me and test the npc chat bot here:
- Using Chat GPT instead of Bard
- Managing prompts (Making bot act as our assistant)
0 voters
Heres how making bot act as our assistant will look like:
Thanks!