Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'superagent-proxy' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
/* @flow */
import superagent from 'superagent';
import superagentProxy from 'superagent-proxy';
import AgentKeepAlive from 'agentkeepalive';
let keepAliveAgent: (AgentKeepAlive | AgentKeepAlive.HttpsAgent) = null;
let keepAliveSecureAgent: (AgentKeepAlive | AgentKeepAlive.HttpsAgent) = null;
superagentProxy(superagent);
export function proxy(superagentConstruct: superagent) {
return superagentConstruct.proxy(this._config.proxy);
}
export function keepAlive(superagentConstruct: superagent) {
let agent = this._config.secure ? keepAliveSecureAgent : keepAliveAgent;
if (agent === null) {
let AgentClass = this._config.secure ? AgentKeepAlive.HttpsAgent : AgentKeepAlive;
agent = new AgentClass(this._config.keepAliveSettings);
if (this._config.secure) {
keepAliveSecureAgent = agent;
} else {
keepAliveAgent = agent;
}
}
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
import constants from '../constants'
import { Response, RecastError } from '../resources'
const agent = superagentPromise(superagentProxy(superagent), Promise)
export default class Request {
constructor (token, language) {
this.token = token
this.language = language
}
textRequest = async (text, options = {}) => {
const token = options.token || this.token
const proxy = options.proxy
const data = { text, language: options.language || this.language }
if (!token) { throw new RecastError('Parameter token is missing') }
try {
const request = agent('POST', constants.REQUEST_ENDPOINT)
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
import constants from '../constants'
import { Conversation, RecastError } from '../resources'
const agent = superagentPromise(superagentProxy(superagent), Promise)
export default class Converse {
constructor (token, language) {
this.token = token
this.language = language
}
textConverse = async (text, options = {}) => {
const token = options.token || this.token
const proxy = options.proxy
const data = {
text,
language: options.language || this.language,
conversation_token: options.conversationToken,
memory: options.memory,
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
const agent = superagentPromise(superagentProxy(superagent), Promise)
import constants from '../constants'
export default class Build {
constructor (token, language) {
this.token = token
this.language = language
}
dialog = (message, options = {}, memory = null, log_level = 'info') => {
const token = options.token || this.token
const proxy = options.proxy
const data = {
message,
conversation_id: options.conversationId,
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
const agent = superagentPromise(superagentProxy(superagent), Promise)
import constants from '../constants'
import { Message } from '../resources'
export default class Connect {
constructor (token) {
this.token = token
}
handleMessage = (req, res, onMessageReceived) => {
if (typeof res.status === 'function') {
res.status(200).send()
} else {
res.status = 200
}
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
import constants from '../constants'
const agent = superagentPromise(superagentProxy(superagent), Promise)
export default class Conversation {
constructor ({ conversation_token, next_actions, ...response }) {
for (const key in response) {
this[key] = response[key]
}
this.nextActions = next_actions
this.conversationToken = conversation_token
}
/**
* Returns the first reply if there is one
* @returns {String}: this first reply or null
*/
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
const agent = superagentPromise(superagentProxy(superagent), Promise)
import constants from '../constants'
import { Message } from '../resources'
export default class Connect {
constructor (token) {
this.token = token
}
handleMessage = (req, res, onMessageReceived) => {
if (typeof res.status === 'function') {
res.status(200).send()
} else {
res.status = 200
}
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
import constants from '../constants'
const agent = superagentPromise(superagentProxy(superagent), Promise)
export default class Message {
constructor (body, sapcaiToken) {
for (const key in body) {
this[key] = body[key]
}
this.content = body.message.attachment.content
this.type = body.message.attachment.type
this.conversationId = body.message.conversation
this.sapcaiToken = sapcaiToken
this._messageStack = []
}
addReply = (replies) => this._messageStack = this._messageStack.concat(replies)
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
import constants from '../constants'
import { SapcaiError } from '../resources'
import Bots from './bots'
import Entities from './entities'
import Gazettes from './gazettes'
import Intents from './intents'
import Logs from './logs'
const agent = superagentPromise(superagentProxy(superagent), Promise)
export default class Train {
constructor (token, language, version, userSlug, botSlug) {
if (typeof userSlug !== 'string' || typeof botSlug !== 'string') {
throw new SapcaiError('Train client must be initiated with a user slug and a bot slug')
}
this.token = token
this.language = language
this.userSlug = userSlug
this.botSlug = botSlug
this.botVersion = version
this.bots = new Bots(this)
this.entities = new Entities(this)
import superagent from 'superagent'
import superagentProxy from 'superagent-proxy'
import superagentPromise from 'superagent-promise'
import constants from '../constants'
import { Conversation, Response, SapcaiError } from '../resources'
const agent = superagentPromise(superagentProxy(superagent), Promise)
export default class Request {
constructor (token, language) {
this.token = token
this.language = language
}
/*
* /request (with text string)
*/
analyseText = async (text, options = {}) => {
const token = options.token || this.token
const proxy = options.proxy
const data = { text, language: options.language || this.language }
if (!token) { throw new SapcaiError('Parameter token is missing') }