1.1.5 • Published 10 months ago

botfriends-x-sdk v1.1.5

Weekly downloads
16
License
ISC
Repository
-
Last release
10 months ago

BOTfriends X SDK

alt text

BOTfriends X SDK helps you interact with the BOTfriends X Platform. It is designed to give you the opportunity to create custom integrations. You can run event requests to the used nlp service and create your own responses with it.

Installation

npm install botfriends-x-sdk

Usage

const { BotfriendsClient } = require('botfriends-x-sdk')

// init your client
const bfClient = new BotfriendsClient('some-jwt')

const textResponse = bfclient.message.createTextResponse('some text')

// ...

Methods

Handover

MethodDescription
deleteUserMessagesto delete messages of a user
exportConversationsto export conversations
exportUserMessagesto export messages of a user
exportProjectMessagesto export all messages of the project
getOnlineAgentsto get agents that are currently online
startHandoverto start the handover for a conversation
isInHoursOfOperationto check if currently inside hours of operation

deleteUserMessages

const userId : String

bfClient.handover.deleteUserMessages(userId)

exportConversations

const userId : String

const exportResponse = bfClient.handover.exportConversations()

exportResponse = [{
  ...
]}

exportUserMessages

const userId : String

const exportResponse = bfClient.handover.exportUserMessages(userId)

exportResponse = [{
  ...
]}

exportProjectMessages

const exportResponse = bfClient.handover.exportProjectMessages()

exportResponse = [{
  ...
]}

getOnlineAgents

const onlineAgentsResponse = bfClient.handover.getOnlineAgents()

onlineAgentsResponse = { onlineAgents: Number }

startHandover

const conversationId : String
const options : StartHandoverOptions = {
  ignoreHoursOfOperation?: Boolean,
  ignoreAgentAvailability?: Boolean
}

const startHandoverResponse = bfClient.handover.startHandover(conversationId, options?)

startHandoverResponse = { success: Boolean }

isInHoursOfOperation

const isInHoursOfOperationResponse = bfClient.handover.isInHoursOfOperation()

isInHoursOfOperationResponse = { isInHoursOfOperation: Boolean }

Intent Management

MethodDescription
lastChangesto load the last IM changes
entitiesto load the entities
exportto load the IM export data

lastChanges

const labels? : String[] // Optional, if skipped or invalid, all changes will be returned

const lastChangesResponse = bfClient.im.lastChanges(labels)

lastChangesResponse = {
  id: String,
  notes: String[],
  projectId: String,
  userEmail: String,
  user: String,
  type: String,
  nluId: String,
  updatedKeys: String[],
  timestamp: Number,
  nluService: String,
  intentId: String,
  intentName: String
}

entities

const entitiesResponse = bfClient.im.entities()

entitiesResponse = [{
  id: String,
  name: String,
  type: String,
  nluId: String,
  entities: [{
    entities: [{
        value: String,
        synonyms: String[]
      }
    ],
    languageCode: String
  }]
}],

export

const exportResponse = bfClient.im.export()

exportResponse = {
  intents: IM.Intent[]
  customEntities: IM.CustomEntity[],
  settings: ISettingsExport,
  nluExport: any
}

NLP

MethodDescription
addOutputContextsto add output contexts
deleteAllOutputContextsto delete all output contexts
eventRequestto run an event request
detectIntentto make an intent detection

addOutputContexts

const recipient : String
const contexts : any[]

bfClient.nlp.addOutputContexts(recipient, contexts)

deleteAllOutputContexts

const recipient : String

bfClient.nlp.deleteAllOutputContexts(recipient)

eventRequest

const eventName : String
const recipient : String
const languageCode? : String // Optional: If no language Code is specified, the default language is used
const channel? : String // Optional

const eventRequestResponse = bfClient.nlp.eventRequest(eventName, recipient, languageCode, channel)

eventRequestResponse = {
  invocationType: 'event',
  recipient: String,
  channel: String,
  intentId: String,
  detectedIntent: String,
  intentMetaData: {
    cofidenceScore: Number,
    languageCode: String
  },
  input: String,
  detectedAction: String,
  detectedEvents: [String],
  parameters: any,
  context: {
    inputcontext: any,
    outputcontext: any
  },
  outputs: [
    {
      type: String,
      messageType
    }
  ]
}

detectIntent

const userQuery : String
const recipient : String
const languageCode? : String // Optional: If no language Code is specified, the default language is used
const channel? : String // Optional

const dectIntentResponse = bfClient.nlp.detectIntent(userQuery, recipient, languageCode, channel)

detectIntentResponse = {
  invocationType: 'userQuery',
  recipient: String,
  channel: String,
  intentId: String,
  detectedIntent: String,
  intentMetaData: {
    cofidenceScore: Number,
    languageCode: String
  },
  input: String,
  detectedAction: String,
  detectedEvents: [String],
  parameters: any,
  context: {
    inputcontext: any,
    outputcontext: any
  },
  outputs: [
    {
      type: String,
      messageType
    }
  ]
}

Messages

MethodDescription
createTextResponseto create a botfriends text response
createImageResponseto create a botfriends image response
createCardResponseto create a botfriends card response
createQuickreplyto create a botfriends quickreply response
createQuickreplyElementto create a botfriends quickreply element
createVoiceResponseto create a botfriends voice response
createForwardingMessageto create a botfriends forwarding call response

createTextResponse

const text : String

const textResponse = bfClient.message.createTextResponse(text)

textResponse = {
  type: 'text',
  message: { text: String }
}

createImageResponse

const imageURL : String

const imageRepsonse = bfClient.message.createImageResponse(imageURL)

imageRepsonse = {
  type: 'image',
  message: { image: String }
}

createCardResponse

const title : String
const subtitle? : String
const image? : String
const buttons?: [
  { title: String, postback: String }
]


const cardResponse = bfClient.message.createCardResponse(title, subtitle?, image?, buttons?)

cardResponse = {
  type: 'card',
  message: {
    card: {
      title: String,
      subtitle: String,
      image: String,
      buttons: [
        {
          title: String,
          postback: String
        }
      ]
    }
  }
}

createQuickreply

const text : String
const quickreply : [quickreplyElements]

const quickreplyElementResponse = bfClient.message.createQuickreplyElement(text, quickreply)

quickreplyElementResponse = {
  type: 'quickreply',
  message: {
    text: String,
    quickreply: [quickreplyElements]
  }
}

createQuickreplyElement

const title : String
const postback : String

const quickreplyResponse = bfClient.message.createQuickreply(title, postback)

quickreplyResponse = {
  title: String,
  postback: String
}

createVoiceResponse

const voicemessage : String
const ssml : Boolean


const voiceResponse = bfClient.message.createVoiceResponse(voicemessage, ssml)

voiceResponse = {
  type: 'voice',
  message: {
    voice: String,
    ssml: Boolean
  }
}

createForwardingMessage

const phoneNumber : String

const forwardingCallResponse = bfClient.message.createForwardingMessage(phoneNumber)

forwardingCallResponse = {
  type: 'callForwarding',
  message: {
    phoneNumber: String
  }
}

Send

MethodDescription
textto push text message to a user
outputsto push output messages to a user

text

const userId : String
const message: String
const role?: Role

bfClient.send.text(userId, message, role)

outputs

const userId : String
const outputs: Output[]
const role?: Role

bfClient.send.outputs(userId, outputs, role)

Utils

MethodDescription
extractParamsconverts the Botfriends-X Intent Paramaters to simple key-value object. For example {name: {kind: 'stringValue', stringValue: 'John'}} will result {name: 'John'}
replaceOutputPlaceholdersreplaces placeholders with params in the given intent responses. For example: Params: {name: 'John'}, intent with output: 'Welcome #name!' will result the intent with output: 'Welcome John!'
createContextcreates a Botfriends-X output context
getContextParamreturns context param from the given intent with the given key

extractParams

const parameters : BF-X Parameter

const extractParamsResult = bfClient.utils.extractParams(parameters)

extractParamsResult = {} // any object

replaceOutputPlaceholders

const params : {[key: string]: string}
const intent: BF-X Intent

bfClient.utils.replaceOutputPlaceholders(params, intent)

createContext

const contextBaseUrl : String
const userId : String
const name: String
const params: {[key: string]: string}
const lifespanCount?: Number  // Optional: If no lifespanCount is specified, the default lifespanCount is 1

const createContextResult = bfClient.utils.createContext(contextBaseUrl, userId, name, params, lifespanCount)

createContextResult = {
  name: String
  lifespanCount: Number
  parameters: {
    fields: Parameter
  }
}

getContextParam

const intent: BF-X Intent
const key : String

const getContextParamResult = bfClient.utils.getContextParam(intent, key)

getContextParamResult = String | null

If you have any problems, contact us here

Authors

1.1.5

10 months ago

1.1.4

10 months ago

1.1.3

10 months ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.17

2 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago