Jump to content

AltChat addition Question


FastNEasy

Recommended Posts

Hey everyone,

I am looking for any kind of guide or information on how to add the AltChat chatbot to my script I’m making. I know @ProjectPact and a few other scripters have it in their scripts, and can honestly say it makes a difference. My accounts are lasting much longer, and the conversations are actually really good (and sometimes really funny). I sent @ProjectPact a message, but he has not read it yet.

Any help would be great

Thank You!

Link to comment
Share on other sites

6 hours ago, FastNEasy said:

Hey everyone,

I am looking for any kind of guide or information on how to add the AltChat chatbot to my script I’m making. I know @ProjectPact and a few other scripters have it in their scripts, and can honestly say it makes a difference. My accounts are lasting much longer, and the conversations are actually really good (and sometimes really funny). I sent @ProjectPact a message, but he has not read it yet.

Any help would be great

Thank You!

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;

public class API {

	public static void main(String[] args) throws IOException {
		String message = "Hello, how are you?";
		String email = "EMAIL";
		String apiKey = "API_KEY";
		String token = authenticate(email + ":" + apiKey);

		System.out.println("provided token:" + token);
		System.out.println("please type exit to terminate chat");
		System.out.println("chatbot:" + chat(token, message));
	}

	public static String authenticate(String usrCredit) {
		String userAuth = usrCredit;
		String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(userAuth.getBytes());

		BufferedReader httpResponseReader = null;
		String result = "";
		try {

			// Connect to the web server endpoint
			URL serverUrl = new URL("http://api.altchat.app/login");

			HttpURLConnection urlConnection = (HttpURLConnection) serverUrl.openConnection();

			// Set HTTP method as GET
			urlConnection.setRequestMethod("GET");

			// Include the HTTP Basic Authentication payload
			urlConnection.addRequestProperty("Authorization", basicAuthPayload);

			// Read response from web server, which will trigger HTTP Basic Authentication
			// request to be sent.
			httpResponseReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
			String lineRead;
			while ((lineRead = httpResponseReader.readLine()) != null) {
				result = result + lineRead;
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (httpResponseReader != null) {
				try {
					httpResponseReader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

		result = result.split(":")[1];
		result = result.replaceAll("}", "");
		result = result.replaceAll("\"", "");
		return result;
	}

	public static String chat(String token, String sent) throws IOException {
		URL url = new URL("http://api.altchat.app/" + token);
		HttpURLConnection con = (HttpURLConnection) url.openConnection();
		con.setRequestMethod("POST");
		con.setRequestProperty("Content-Type", "application/json; utf-8");
		con.setRequestProperty("Accept", "application/json");
		con.setDoOutput(true);
		String result = "";
		String jsonInputString = "{\"message\": \"" + sent + "\"}";

		try (OutputStream os = con.getOutputStream()) {
			byte[] input = jsonInputString.getBytes("utf-8");
			os.write(input, 0, input.length);
		}

		try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))) {
			StringBuilder response = new StringBuilder();
			String responseLine = null;
			while ((responseLine = br.readLine()) != null) {
				response.append(responseLine.trim());
			}

			result = response.toString();
		}
		return result;
	}
}

 
Edited by Medusa
Link to comment
Share on other sites

Hi @FastNEasy,

Sorry, I was asleep and didn’t see your private message. I assume you’re referring to hooking it up to your script and not just grabbing the source off their site.

I’ve actually had a lot of people asking how to add it because Cleverbot is definitely not the move anymore lol. Give me a little and I’ll release a snippet for you so you can add it to your script. 

 

 

EDIT: Here you go @FastNEasy

 

Edited by ProjectPact
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...