0.0.68 • Published 4 years ago

wickrio-base v0.0.68

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

WickrIO Bot API

Development Experience

.vscode includes a launch.json for debugging the project in development, and while debugging jest tests. .devenvironment includes a Dockerfile that will set up a container including

The Wickr IO Node.js Bot API Framework provides tools for an easier and more efficient Development of WickrIO integration bots. It utilizes the Wickr IO Node.js Addon API(wickrio_addon) functions to make it easier to develop integrations. For full documentation and usage guide go here: https://wickrinc.github.io/wickrio-docs/#writing-integrations-node-js-bot-api-development-toolkit

To get started, you would need to setup your system, download and install Docker and run the WickrIO Docker container. Full instructions on how to do so are available here: https://wickrinc.github.io/wickrio-docs/#wickr-io-getting-started

Install

npm install --save wickrio-base

Configure

configureNewBot()

async function configureNewBot() {
  // set tokens needed for the app
  const tempbot = new BotAPI({ botName: 'tempbot' })

  const tokenConfig = [
    {
      token: 'WEB_INTERFACE',
      pattern: 'yes|no',
      type: 'string',
      description:
        'Do you want to setup the web interface (REST API or WEB Application) [yes/no]',
      message: 'Please enter either yes or no',
      required: true,
      default: 'no',
      list: [
        {
          token: 'WEB_APPLICATION',
          pattern: 'yes|no',
          type: 'string',
          description: 'Do you want to use the web application [yes/no]',
          message: 'Please enter either yes or no',
          required: true,
          default: 'no',
        },
      ],
    },
  ]
  // set ecosystem file
  const processesFilePath = path.join(__dirname, './processes.json')
  // configure (provision, really).
  await tempbot.configure({
    tokenConfig,
    processesFilePath,
    supportAdministrators: true,
    supportVerification: true,
  })

  process.exit()
}

Usage

import { BotAPI, WickrAPI } from 'wickrio-base'

const bot = new BotAPI({
  botName: JSON.parse(process.env.tokens).WICKRIO_BOT_NAME.value,
})

const startBot = () => {
  try {
    const status = bot.connect()
    // provision bot with bot.provision({ status }) or
    // bot.provision({
    //   status,
    //   setAdminOnly = false,
    //   attachLifeMinutes = "0",
    //   doreceive = "true",
    //   duration = "0",
    //   readreceipt = "true",
    //   cleardb = "true",
    //   contactbackup = "false",
    //   convobackup = "false",
    // })
    bot.provision({ status })

    // Passes a callback function that will receive incoming messages into the bot client
    bot.startListening(listen)
    // await bot.startListening(listen); //Passes a callback function that will receive incoming messages into the bot client
  } catch (err) {
    console.log(err)
  }
}

async function listen(rawMessages) {
  try {
    // listen to messages, receive data
    const {
      command,
      argument,
      message,
      user,
      latitude,
      longitude,
      vgroupid,
      convoType,
      messageType,
      file,
      filename,
      isAdmin,
    } = bot.getMessageData(rawMessages)

    if (command === '/version') {
      const obj = Version.execute()
      WickrAPI.cmdSendRoomMessage(vgroupid, obj.reply)
      return
    }

    if (command === '/help') {
      const helpString =
        '*Messages Commands*\n' +
        '/send <Message> : To send a broadcast message to a given file of user hashes or usernames\n' +
        'To save a file of usernames or user hashes - Click the + sign and share the file with the bot\n'
      const reply = bot.getAdminHelp(helpString)
      // const sMessage = WickrIOAPI.cmdSendRoomMessage(vGroupID, reply);
      WickrAPI.sendRoomMessage(vgroupid, reply)
      return
    }

    const result = {
      command,
      argument,
      message,
      user,
      latitude,
      longitude,
      vgroupid,
      convoType,
      messageType,
      file,
      filename,
      isAdmin,
    }

    if (result) {
      WickrAPI.cmdSendRoomMessage(vgroupid, result)
    }

    // check if user sending message is an admin for commands beyond this point
    // move above anyting that should be blocked for non admins
    if (!isAdmin) {
      const reply = `Hey this bot is just for announcements and can't respond to you personally, or ${user.userEmail} is not authorized to use this bot. If you have a question, please get a hold of us a support@wickr.com or visit us a support.wickr.com. Thanks, Team Wickr`
      WickrAPI.cmdSendRoomMessage(vgroupid, reply)
      // writer.writeFile(message)
      return
    }
  } catch (err) {}
}

For a full usage and easy to get started example see: https://github.com/amlcodes/wickrio-basic-bot

0.0.68

4 years ago

0.0.66

4 years ago

0.0.67

4 years ago

0.0.65

4 years ago

0.0.62

4 years ago

0.0.63

4 years ago

0.0.64

4 years ago

0.0.61

4 years ago

0.0.5

4 years ago

0.0.60

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago