Template Content
About the template
About ScriptRunner Connect
What is ScriptRunner Connect?
Can I try it out for free?
Yes. ScriptRunner Connect comes with a forever free tier.
Can I customize the integration logic?
Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.
Can I change the integration to communicate with additional apps?
Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.
What if I don't feel comfortable making changes to the code?
First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.
Do I have to host it myself?
No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.
What about security?
ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.
generic connector
, add a custom header with the following details:https://api.openai.com
Authorization
Bearer YOUR_OPENAI_API_KEY
AUTH_KEY
configured via Parameters
. (Update the key as desired).import { HttpEventRequest, HttpEventResponse, buildJSONResponse } from '@sr-connect/generic-app/events/http';
import OpenAI from './api/openai';
/**
* When invoked, this function accepts the question, forwards it to OpenAI and replies with the answer.
*/
export default async function (event: HttpEventRequest, context: Context): Promise<HttpEventResponse> {
try {
if (context.triggerType === 'MANUAL') {
console.error('This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.');
return;
}
const { API_KEY } = context.environment.vars as EnvVars;
// Check if the incoming request has approriate API key
if (event.body.auth !== API_KEY) {
return buildJSONResponse({
response: "Sorry, your API key isn't working. Might want to double check that."
});
}
// Extract the question
const question = event.body.prompt;
// Log out the question
console.log(`Question: ${event.body.prompt}`);
// Forward the question to ChatGPT
const response = await OpenAI.fetch('/chat/completions', {
method: "POST",
body: JSON.stringify({
"model": "gpt-4-1106-preview",
"messages": [
{
"role": "system",
"content": `You are a helpful assistant. Be kind and courteous and respond respectfully. Be brief, as your response will be broadcast on a speaker.`
},
{
"role": "user",
"content": question
}
]
})
});
// Extract the response message
const responseMessage = await response.json<OpenAIResponse>();
// Check if the message contains an error
if (responseMessage.error) {
// If so, then throw an error
throw new Error(responseMessage.error.message);
}
// Extract the answer
const answer = responseMessage.choices.map(ch => ch.message.content).join(' ');
// Finally return the answer
return buildJSONResponse({
response: answer
})
} catch (e) {
// If error was thrown, log it out
console.log('Error while processing request', e);
// And respond appropriately
return buildJSONResponse({
response: `Something went wrong while asking your question`
});
}
}
interface EnvVars {
readonly API_KEY: string;
}
interface OpenAIResponse {
choices: {
message: Message;
}[];
error?: {
message: string;
}
}
interface Message {
role: string;
content: string;
}