REST-API interface

Set of ready-made procedures, functions for service INB.AI

Get API key

Statistics for 30 days - the data is updated every minute.

Methods АPI

  • Access:
method
description
group

getTokenSocket
Get user auth token session
Auth

  • Information about the method.
    Method name:getTokenSocket
    Method URL:https://api.inb.ai/api/v1/getTokenSocket
    Access level:Private API (User access)
    Тип:all
    Description of the method
    token live 3min or 1 coonnect


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.tokentoken hash stringHfgas3251fsa
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/getTokenSocket
    Send
    Key
    Value
    Description
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code of the method:

      return new Promise((resolve, reject) => {
          if (user && user.user && user.user._id)
              resolve(true);
          else
              resolve(false);
      })
          .then(statusAuth => {
              if (!statusAuth) return false;
              return db.AuthSocketToken.remove({user: user.user._id}).then(() => {
                  return true
              });
          }).then((statusAuth) => {
              if (!statusAuth) return {token: 'public'};
      
      
              const token = passwordUtils.generateToken();
              return db.AuthSocketToken.create({
                  user: user.user._id,
                  token: token,
                  created_at: Date.now()
              }).then(() => {
                  return {token}
              })
          })
          .catch(API.error.validate);

isAuthUser
Check authorization user
Auth

  • Information about the method.
    Method name:isAuthUser
    Method URL:https://api.inb.ai/api/v1/isAuthUser
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/isAuthUser
    Send
    Key
    Value
    Description
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code of the method:

      (auth, param) => {
      return db.User
          .findOne({_id: mongoose.Types.ObjectId(auth.user._id)})
          .select({
              _id: 1,
              address: 1,
              email: 1,
              first_name: 1,
              last_name: 1,
              date_of_birth: 1,
              updatedAt: 1,
              createdAt: 1,
              active: 1,
              partner: 1,
              deleted: 1,
              accountIdService1: 1,
              deleted_reason: 1,
          })
          .then(usr => {
              return {
                  _id: usr._id,
                  address: usr.address,
                  email: usr.email,
                  firstName: usr.first_name,
                  lastName: usr.last_name,
                  date_of_birth: usr.date_of_birth,
                  createdAt: usr.createdAt,
                  updatedAt: usr.updatedAt,
                  active: usr.active,
                  partnerId: usr.partner,
                  deleted: usr.deleted,
                  accountIdService1: (usr.accountIdService1 && usr.accountIdService1 !== '') ? usr.accountIdService1 : false,
                  deleted_reason: usr.deleted_reason,
              }
          })
          .catch(API.error.validate);
      

loginUseHash
Login to account with HASH
Auth

  • Information about the method.
    Method name:loginUseHash
    Method URL:https://api.inb.ai/api/v1/loginUseHash
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    addresspublic key (address)STRINGNO
    hashkeccak256(private_key)STRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.tokentoken hash stringHfgas3251fsa
    data.user_iduser id login in account2
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/loginUseHash
    Send
    Key
    Value
    Description
    address
    public key (address)
    hash
    keccak256(private_key)
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name address @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name hash @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      (auth, param) => {
      return new Promise((resolve, reject) => {
      
          resolve({address: param.address, hash: param.hash});
      })
      
          .then((opt) => {
              return db.User.findOne({publicKey: opt.address})
                  .then(usr => {
      
      
                      if (!usr) return Promise.reject(API.error.create('User is not found', 'api', {}, 0, 241351));
                      let blockedUnix = usr.blockingEndTime && usr.blockingEndTime.getTime ? usr.blockingEndTime.getTime() : 0;
                      let blockedTimeEnd = blockedUnix - new Date().getTime();
                      if (blockedTimeEnd > 0) return Promise.reject(API.error.create('User blocked wait: ' + (blockedTimeEnd / (1000 * 60)).toFixed(0) + ' min.(' + usr.blockingReason + ')', 'api', {}, 0, 63426324));
      
                      if (!usr.comparePassword(param.hash)) return Promise.reject(API.error.create('Error hash', 'api', {}, 0, 543264363444));
      
                      if (usr.deleted) return Promise.reject(API.error.create('Account deleted', 'api', {deleted_reason: usr.deleted_reason}, 0, 532162316));
                      if (!usr.active) return Promise.reject(API.error.create('Account is not active please active', 'api', {}, 0, 2355231636112));
                      auth.session.userAuth = true;
                      auth.session.userId = usr._id;
                      return {
                          _id: usr._id,
                          address: usr.publicKey,
                          email: usr.email,
                          firstName: usr.first_name,
                          lastName: usr.last_name,
                          nickname: usr.nickname,
                          dateOfBirth: usr.date_of_birth,
                          createdAt: usr.createdAt,
                          updatedAt: usr.updatedAt,
                          active: usr.active,
                          deleted: usr.deleted,
                          accountIdService1: (usr.accountIdService1 && usr.accountIdService1 !== '') ? usr.accountIdService1 : false,
                          deleted_reason: usr.deleted_reason,
                      }
                  })
                  .catch(err => {
                      return Promise.reject(API.error.create(err.message, 'api', {opt}, 0, 53256));
                  });
      
          })
          .catch(API.error.validate);

destroySession
Login to account with email
Auth

  • Information about the method.
    Method name:destroySession
    Method URL:https://api.inb.ai/api/v1/destroySession
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/destroySession
    Send
    Key
    Value
    Description
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code of the method:

      (auth, param) => {
      return new Promise((resolve, reject) => {
          auth.session.destroy();
          resolve({});
      })
      
          .catch(API.error.validate);

registerUseHash
Register a new account by HASH
Auth

  • Information about the method.
    Method name:registerUseHash
    Method URL:https://api.inb.ai/api/v1/registerUseHash
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    addresspublic key (address)STRINGNO
    hashkeccak256(private_key)STRINGNO
    partnerIdpartnerIdSTRINGNO
    nicknamenicknameSTRINGNO
    firstNameNameSTRINGNO
    lastNameSurnameSTRINGNO
    emailEmailSTRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.tokentoken hash stringHfgas3251fsa
    data.user_iduser id login in account2
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/registerUseHash
    Send
    Key
    Value
    Description
    address
    public key (address)
    hash
    keccak256(private_key)
    partnerId
    partnerId
    nickname
    nickname
    firstName
    Name
    lastName
    Surname
    email
    Email
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name address @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name hash @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name partnerId @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name nickname @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name firstName @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name lastName @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name email @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      (auth, param) => {
      return new Promise((resolve, reject) => {
      
      
          param.email = param.email.replace(/\s/g, '').toLowerCase();
      
          resolve({
              address: param.address,
              hash: param.hash,
              email: param.email,
              first_name: param.firstName || '',
              last_name: param.lastName || '',
              nickname: param.nickname || '',
              partnerId: (param.partnerId && !mongoose.Types.ObjectId.isValid(param.partnerId)) ? mongoose.Types.ObjectId(param.partnerId) : undefined,
      
          });
      })
      
          .then((opt) => {
              return new db.User({
                  publicKey: opt.address,
                  email: opt.email,
                  secureHash: opt.hash,
                  partner: opt.partnerId,
                  first_name: opt.first_name,
                  last_name: opt.last_name,
                  nickname: opt.nickname,
                  active: true
      
              })
                  .save()
                  .then(usr => {
                      return {
                          _id: usr._id,
                          address: usr.address,
                          email: usr.email,
                          firstName: usr.first_name,
                          lastName: usr.last_name,
                          affiliate: usr.affiliate,
                          date_of_birth: usr.date_of_birth,
                          createdAt: usr.createdAt,
                          updatedAt: usr.updatedAt,
                          active: usr.active,
                          partnerId: usr.partner,
                          deleted: usr.deleted,
                          accountIdService1: (usr.accountIdService1 && usr.accountIdService1 !== '') ? usr.accountIdService1 : false,
                          deleted_reason: usr.deleted_reason,
                      }
                  })
                  .catch(err => {
                      if (err.code === 11000) return Promise.reject(API.error.create('Address already in use', 'api', {}, 0, 7321529880878564));
                      return Promise.reject(API.error.create(err.message, 'api', {opt}, 0, 4611529880882953));
                  })
          })
          .catch(API.error.validate);

registerService1
Register a new account in Service1
Auth

  • Information about the method.
    Method name:registerService1
    Method URL:https://api.inb.ai/api/v1/registerService1
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    emailEmailSTRINGNO
    passwordPasswordSTRINGNO
    firstNameNameSTRINGNO
    lastNameSurnameSTRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.iduser id login in account2
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/registerService1
    Send
    Key
    Value
    Description
    email
    Email
    password
    Password
    firstName
    Name
    lastName
    Surname
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name email @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name password @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name firstName @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name lastName @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      (auth, param) => {
      return API.proxy.Service1('POST:user', {service: 1}, {
          get: {},
          post: {
              'email': param.email,
              'password': param.password,
              'name': param.firstName,
              'surname': param.lastName,
              'country': 'US',
              'site_lang': 'ru',
              'callback_url': '',
          }
      })
          .then(res => {
              return API.proxy.Service1('GET:auth/token', {}, {
                  get: {
                      'email': param.email,
                      'password': param.password,
                      'callback_url': '',
                      '2auth_code': '',
                      '2auth_type': ''
                  },
                  post: {}
              });
          })
          .then(res => {
              return db.User
                  .findOneAndUpdate({_id: mongoose.Types.ObjectId(auth.user._id)}, {
                      $set: {
                          accountIdService1: res.id,
                          accountTokenService1: encryptionUtils.encryptAes256cbc(res.token),
                      }
                  }, {new: true})
                  .then(usr => {
                      return {
                          _id: usr._id,
                          address: usr.address,
                          email: usr.email,
                          firstName: usr.first_name,
                          lastName: usr.last_name,
                          date_of_birth: usr.date_of_birth,
                          createdAt: usr.createdAt,
                          updatedAt: usr.updatedAt,
                          active: usr.active,
                          partnerId: usr.partner,
                          deleted: usr.deleted,
                          accountIdService1: (usr.accountIdService1 && usr.accountIdService1 !== '') ? usr.accountIdService1 : false,
                          deleted_reason: usr.deleted_reason,
                      }
                  })
      
          })
          .catch((err) => {
              console.log(err);
              return Promise.reject(API.error.create(err.body.error, 'api', {}, 0, +('99472' + err.body.code)));
          })
          .catch(API.error.validate);

loginService1
Auth in Service1
Auth

  • Information about the method.
    Method name:loginService1
    Method URL:https://api.inb.ai/api/v1/loginService1
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    emailEmailSTRINGNO
    passwordPasswordSTRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.iduser id login in account2
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/loginService1
    Send
    Key
    Value
    Description
    email
    Email
    password
    Password
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name email @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name password @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      (auth, param) => {
      return Promise.resolve()
          .then(res => {
              return API.proxy.Service1('GET:auth/token', {}, {
                  get: {
                      'email': param.email,
                      'password': param.password,
                      'callback_url': '',
                      '2auth_code': '',
                      '2auth_type': ''
                  },
                  post: {}
              });
          })
          .then(res => {
              return db.User
                  .findOneAndUpdate({_id: mongoose.Types.ObjectId(auth.user._id)}, {
                      $set: {
                          accountIdService1: res.id,
                          accountTokenService1: encryptionUtils.encryptAes256cbc(res.token),
                      }
                  }, {new: true})
                  .then(usr => {
                      return {
                          _id: usr._id,
                          address: usr.address,
                          email: usr.email,
                          firstName: usr.first_name,
                          lastName: usr.last_name,
                          date_of_birth: usr.date_of_birth,
                          createdAt: usr.createdAt,
                          updatedAt: usr.updatedAt,
                          active: usr.active,
                          partnerId: usr.partner,
                          deleted: usr.deleted,
                          accountIdService1: (usr.accountIdService1 && usr.accountIdService1 !== '') ? usr.accountIdService1 : false,
                          deleted_reason: usr.deleted_reason,
                      }
                  })
      
          })
          .catch((err) => {
              console.log(err);
              return Promise.reject(API.error.create(err.body.error, 'api', {}, 0, +('99472' + err.body.code)));
          })
          .catch(API.error.validate);

btcMultiTransfer
Bitcoin Multi Transfer
MultiSender

  • Information about the method.
    Method name:btcMultiTransfer
    Method URL:https://api.inb.ai/api/v1/btcMultiTransfer
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    addressFrom addressSTRINGNO
    to[].addresssend to addressSTRINGNO
    to[].amountamountFLOATNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.okok==11
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/btcMultiTransfer
    Send
    Key
    Value
    Description
    address
    From address
    to[][address]
    send to address
    to[][amount]
    amount
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name address @type STRING
      @var max=100
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name to @type Array
      */ // =====================================

    Source code of the method:

      return bitcoin.sendTransactions({
          from: param.address,
          to: param.to,
          network: 'mainnet',
          dryrun: true
      });

ethMultiTransfer
ETH Multi Transfer
MultiSender

  • Information about the method.
    Method name:ethMultiTransfer
    Method URL:https://api.inb.ai/api/v1/ethMultiTransfer
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    to[].addresssend to addressSTRINGNO
    to[].amountamountFLOATNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.okok==11
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/ethMultiTransfer
    Send
    Key
    Value
    Description
    to[][address]
    send to address
    to[][amount]
    amount
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name to @type Array
      */ // =====================================

    Source code of the method:

      let tx = eth.sendTransactions({
          to: param.to,
      });
      return tx

secureCheckOTP
Check 2fa data
SecureOTP

  • Information about the method.
    Method name:secureCheckOTP
    Method URL:https://api.inb.ai/api/v1/secureCheckOTP
    Access level:Private API (User access)
    Тип:all
    Description of the method
    if use user API don`t send "identy" and "hash"


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    identityYou identity (user_id)STRINGNO
    codeYou code from auth APPINTEGERNO
    unixTimeunix time stampSTRINGNO
    hashsha256HMAC(param.identity+":"+param.unixTime,_SECRET_) STRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.okok==11
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/secureCheckOTP
    Send
    Key
    Value
    Description
    identity
    You identity (user_id)
    code
    You code from auth APP
    unixTime
    unix time stamp
    hash
    sha256HMAC(param.identity+":"+param.unixTime,_SECRET_)
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name identity @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name code @type INTEGER
      @var max=20
      */ valid(v) { if (!v) return {success: false, error: 'Value undefined'}; v = Number(v); if (typeof v !== 'number') return {success: false, error: 'Value is not string'}; if (isNaN(v)) return {success: false, error: 'Value NaN'}; if (!isFinite(v)) return {success: false, error: 'Value Infinity'}; if (String(v).length > this.max) return {success: false, error: 'Value length > ' + this.max}; // Gaussovo (bank rounding) let d = this.fixed || 0, m = Math.pow(10, d), n = +(d ? v * m : v).toFixed(8), i = Math.floor(n), f = n - i, e = 1e-8, r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 === 0) ? i : i + 1) : Math.round(n); v = d ? r / m : r; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name unixTime @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name hash @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      (auth, param) => {
      const hashCheck = crypto.createHmac('sha256', config.get('crypto:secure_otp2fa')).update(param.identity + ':' + param.unixTime).digest('hex');
      if (hashCheck !== param.hash)
          return Promise.reject(API.error.create('Error hash', 'api', {}, 0, 3751530988102253)).catch(API.error.validate);
      
      return db.Auth2fa.findOne({identity: param.identity})
          .then(res => {
              if (!res) return Promise.reject(API.error.create('User don`t used 2fa authorization', 'api', {}, 0, 7191530998992231));
              return res;
      
          })
          .then(res2fa => {
              return {
                  res2fa,
                  status: Auth_2fa.totp.verify({
                      secret: res2fa.secretKey,
                      encoding: 'base32',
                      token: param.code
                  })
              }
          })
          .then(({res2fa, status}) => {
              if (!status) return Promise.reject(API.error.create('Error 2fa code', 'api', {}, 0, 3571530999915038));
              if (!res2fa.active) {
                  return db.Auth2fa.updateOne({_id: res2fa._id}, {
                      $set: {
                          active: true,
                      }
                  }, {new: true}).then(() => {
                      return {status, update2fa: true};
                  });
              }
              return {status};
      
          })
          .catch(API.error.validate);
      
      

secureGetStatusOTP
Get status 2fa
SecureOTP

  • Information about the method.
    Method name:secureGetStatusOTP
    Method URL:https://api.inb.ai/api/v1/secureGetStatusOTP
    Access level:Private API (User access)
    Тип:all
    Description of the method
    if use user API don`t send "identy" and "hash"


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    identityYou identity (user_id)STRINGNO
    unixTimeunix time stampSTRINGNO
    hashsha256HMAC(param.identity+":"+param.unixTime,_SECRET_) STRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.okok==11
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/secureGetStatusOTP
    Send
    Key
    Value
    Description
    identity
    You identity (user_id)
    unixTime
    unix time stamp
    hash
    sha256HMAC(param.identity+":"+param.unixTime,_SECRET_)
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name identity @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name unixTime @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name hash @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      (auth, param) => {
      const hashCheck = crypto.createHmac('sha256', config.get('crypto:secure_otp2fa')).update(param.identity + ':' + param.unixTime).digest('hex');
      if (hashCheck !== param.hash)
          return Promise.reject(API.error.create('Error hash', 'api', {}, 0, 3751530988102253)).catch(API.error.validate);
      
      return db.Auth2fa.findOne({identity: param.identity,active:true})
          .then(res => {
              if (!res) return {active:false};
              return {active:true};
      
          })
      
          .catch(API.error.validate);
      
      

secureCreateOTP
Generate 2fa data
SecureOTP

  • Information about the method.
    Method name:secureCreateOTP
    Method URL:https://api.inb.ai/api/v1/secureCreateOTP
    Access level:Private API (User access)
    Тип:all
    Description of the method
    if use user API don`t send "identy" and "hash"


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    identityYou identity (user_id)STRINGNO
    userTagYou identity (user_id)STRINGNO
    unixTimeunix time stampSTRINGNO
    hashsha256HMAC(param.identity+":"+param.unixTime,_SECRET_) STRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.okok==11
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/secureCreateOTP
    Send
    Key
    Value
    Description
    identity
    You identity (user_id)
    userTag
    You identity (user_id)
    unixTime
    unix time stamp
    hash
    sha256HMAC(param.identity+":"+param.unixTime,_SECRET_)
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name identity @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name userTag @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name unixTime @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name hash @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      (auth, param) => {
      const hashCheck = crypto.createHmac('sha256', config.get('crypto:secure_otp2fa')).update(param.identity + ':' + param.unixTime).digest('hex');
      if (hashCheck !== param.hash)
          return Promise.reject(API.error.create('Error hash', 'api', {}, 0, 3751530988102253)).catch(API.error.validate);
      
      return db.Auth2fa.findOne({identity: param.identity, active: true}).then(res => {
          if (!res) return Promise.resolve(Auth_2fa.generateSecret({
              name: config.get('projectName') + ' (' + ((!!param.userTag && param.userTag.length > 0) ? param.userTag : param.identity) + ')',
              length: 10
          }));
          return Promise.reject(API.error.create('User already uses 2fa authorization', 'api', {}, 0, 6651530988096545))
      }).then(secret => {
          return new Promise((resolve, reject) => {
              QRCode.toDataURL(secret.otpauth_url, function (err, data_url) {
                  if (err)
                      return reject(err);
                  return resolve(data_url);
              });
          })
              .then(image => {
                  return db.Auth2fa.updateOne({identity: param.identity}, {
                      $set: {
                          identity: param.identity,
                          active: false,
                          secretKey: secret.base32
                      }
                  }, {upsert: true, new: true}).then(result => {
                      return {otp: {url: secret.otpauth_url, secret: secret.base32, image}}
      
                  });
      
              })
      }).catch(API.error.validate);
      
      

testAPI
Test API
Test

  • Information about the method.
    Method name:testAPI
    Method URL:https://api.inb.ai/api/v1/testAPI
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.okok==11
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/testAPI
    Send
    Key
    Value
    Description
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code of the method:

      return Promise.resolve({ok: 1})

editUser
Edit user
User

  • Information about the method.
    Method name:editUser
    Method URL:https://api.inb.ai/api/v1/editUser
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    idUser idSTRINGNO
    first_nameUser id is use for edit profileSTRINGNO
    last_nameUser last name is use for edit profileSTRINGNO
    emailUser email is use for edit profile STRINGNO
    rate User rate is use for edit profile FLOATNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.successIf success true == 11
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/editUser
    Send
    Key
    Value
    Description
    id
    User id
    first_name
    User id is use for edit profile
    last_name
    User last name is use for edit profile
    email
    User email is use for edit profile
    rate
    User rate is use for edit profile
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name id @type STRING
      @var max=100
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name first_name @type STRING
      @var max=100
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name last_name @type STRING
      @var max=100
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name email @type STRING
      @var max=100
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name rate @type FLOAT
      @var max=10
      @var fixed=3
      */ valid(v) { if (!v) return {success: false, error: 'Value undefined'}; v = Number(v); if (typeof v !== 'number') return {success: false, error: 'Value is not string'}; if (isNaN(v)) return {success: false, error: 'Value NaN'}; if (!isFinite(v)) return {success: false, error: 'Value Infinity'}; if (String(v).length > this.max) return {success: false, error: 'Value length > ' + this.max}; // Gaussovo (bank rounding) let d = this.fixed || 0, m = Math.pow(10, d), n = +(d ? v * m : v).toFixed(8), i = Math.floor(n), f = n - i, e = 1e-8, r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 === 0) ? i : i + 1) : Math.round(n); v = d ? r / m : r; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      return new Promise((resolve, reject) => {
          if (!param.id) return reject(API.error.create('Param user id undefined', 'api', {}, 0, 8101527705463430));
          if (param.id && !mongoose.Types.ObjectId.isValid(param.id)) return reject(API.error.create('param user id is not valid', 'api', {}, 0, 8311527705473035));
      
          return resolve();
      }).then(() => {
          return db.User.update({_id: mongoose.Types.ObjectId(param.id)},
              {
                  $set: {
                      first_name: param.first_name,
                      last_name: param.last_name,
                      email: param.email,
                      "affiliate.rate": param.rate
                  }
      
              });
      },).then(res => {
          console.log(res);
          if (!res || res.nModified !== 1)
              return Promise.reject(API.error.create('Edit user error', 'api', {resdb: res}, 0, 4551527705877408));
          return {ok: 1};
      }).catch(API.error.validate)

findOrCreateThread
Find or Create dialog row
messenger

  • Information about the method.
    Method name:findOrCreateThread
    Method URL:https://api.inb.ai/api/v1/findOrCreateThread
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    recipientAddress[]addressSTRINGNO
    groupNamegroup NameSTRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    data.idid dialogs1
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/findOrCreateThread
    Send
    Key
    Value
    Description
    recipientAddress[]
    address
    groupName
    group Name
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name recipientAddress @type Array
      */ // =====================================
      /** @name groupName @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      return new Promise((resolve, reject) => {
          return db.User
              .findById(mongoose.Types.ObjectId(user.user._id), {
                  publicKey: 1,
                  nickname: 1
              })
              .then(sender => {
                  return resolve({sender});
              });
      
      })
      
          .then(({sender}) => {
              if (param.recipientAddress.length === 1)
                  return db.Thread.findOne({
                      isGroup: false,
                      $and: [{
                          users: {$elemMatch: {address: sender.publicKey}}
                      }, {
                          users: {$elemMatch: {address: param.recipientAddress[0]}}
                      }]
                  }).then(res => {
      
                      return {res, sender};
                  }).catch(err => {
                      return Promise.reject(API.error.create(err.message, 'api', err, 1, 432662363547));
                  });
              return {res: null, sender}
          })
          .then(({res, sender}) => {
              if (res && res._id) {
                  let recipientIndex = 0;
                  for (let index in res.users) {
                      if (res.users.hasOwnProperty(index) && res.users[index] && res.users[index].address && res.users[index].address !== sender.publicKey) {
                          recipientIndex = +index;
                      }
                  }
      
                  return {...res._doc, recipientIndex}
              }
      
      
              return Promise.map(param.recipientAddress, (recipientAddress) => {
                  return db.User.findOne({publicKey: recipientAddress})
                      .then(usr => {
                          if (!usr) return Promise.reject('not found user');
                          return {
                              recipient: {
                                  user: usr._id,
                                  nickname: usr.nickname
                              }
                          }
                      })
                      .catch(() => {
                          return Profile.getNicknameByAddress(recipientAddress)
                              .then((recipient) => ({
                                  recipient: {...recipient, user: null}
                              }))
                              .catch(() => ({
                                  recipient: {
                                      user: null,
                                      nickname: recipientAddress
                                  }
                              }))
                      }).then(({recipient}) => {
      
                          return {
                              user: recipient.user,
                              address: recipientAddress,
                              nickname: recipient.nickname,
                              isDeleted: false,
                              isAdmin: false,
                              accessWrite: true,
                          }
                      });
      
              })
                  .then((recipients) => {
                      return db.Thread
                          .create({
                              users: [{
                                  user: user.user._id,
                                  address: sender.publicKey,
                                  nickname: sender.nickname,
                                  isDeleted: false,
                                  isAdmin: false,
                                  accessWrite: true,
                              }, ...recipients],
                              isGroup: (recipients.length > 1),
                              groupName: (recipients.length > 1) ? param.groupName || 'Group #' + Date.now() : '',
                          })
                          .then(item => {
                              // redis.publishAPI('createThread', user, res);
                              let recipientIndex = 0;
                              for (let index in item.users) {
                                  if (item.users.hasOwnProperty(index) && item.users[index] && item.users[index].address && item.users[index].address !== sender.publicKey) {
                                      recipientIndex = +index;
                                  }
                              }
                              return {...item._doc, recipientIndex}
                          })
                          .then(res => {
                              if (!res.isGroup)
                                  return res;
      
                              return API.call('createMessage', user, {
                                  threadId: res._id,
                                  message: 'Created group:' + res.groupName
                              }).then(() => {
                                  return res;
                              }).catch(() => {
                                  return res;
                              });
                          })
                  })
      
          })
          .catch(API.error.validate);

getThreads
Get my dialogs list
messenger

  • Information about the method.
    Method name:getThreads
    Method URL:https://api.inb.ai/api/v1/getThreads
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    pagePage numberINTEGERNO
    limitLimit rows on the page INTEGERNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/getThreads
    Send
    Key
    Value
    Description
    page
    Page number
    limit
    Limit rows on the page
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name page @type INTEGER
      @var max=10
      */ valid(v) { if (!v) return {success: false, error: 'Value undefined'}; v = Number(v); if (typeof v !== 'number') return {success: false, error: 'Value is not string'}; if (isNaN(v)) return {success: false, error: 'Value NaN'}; if (!isFinite(v)) return {success: false, error: 'Value Infinity'}; if (String(v).length > this.max) return {success: false, error: 'Value length > ' + this.max}; // Gaussovo (bank rounding) let d = this.fixed || 0, m = Math.pow(10, d), n = +(d ? v * m : v).toFixed(8), i = Math.floor(n), f = n - i, e = 1e-8, r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 === 0) ? i : i + 1) : Math.round(n); v = d ? r / m : r; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name limit @type INTEGER
      @var max=10
      */ valid(v) { if (!v) return {success: false, error: 'Value undefined'}; v = Number(v); if (typeof v !== 'number') return {success: false, error: 'Value is not string'}; if (isNaN(v)) return {success: false, error: 'Value NaN'}; if (!isFinite(v)) return {success: false, error: 'Value Infinity'}; if (String(v).length > this.max) return {success: false, error: 'Value length > ' + this.max}; // Gaussovo (bank rounding) let d = this.fixed || 0, m = Math.pow(10, d), n = +(d ? v * m : v).toFixed(8), i = Math.floor(n), f = n - i, e = 1e-8, r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 === 0) ? i : i + 1) : Math.round(n); v = d ? r / m : r; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      const page = API.plugin.pageAPI.get(param.page, param.limit, {
          maxPage: 200,
          maxLimit: 200,
          defaultPage: 1,
          defaultLimit: 50
      });
      return new Promise((resolve, reject) => {
          return db.User
              .findById(mongoose.Types.ObjectId(user.user._id), {
                  publicKey: 1,
                  nickname: 1
              })
              .then(sender => {
                  return resolve({sender});
              });
      
      })
      
          .then(({sender}) => {
              return new Promise((resolve, reject) => {
                  db.Thread
                      .aggregate([
                          {
                              $match: {
                                  $and: [{
                                      users: {$elemMatch: {address: sender.publicKey}}
                                  }]
                              }
                          },
                          {
                              $lookup: {
                                  from: "messages",
                                  localField: "_id",
                                  foreignField: "thread",
                                  as: "messages",
                                  // "unwinding" : "$messages",
                              }
                          },
      
                          {$unwind: {path: "$messages"}},
                          {
                              "$group": {
                                  _id: "$_id",
                                  users: {"$first": "$users"},
                                  isGroup: {"$first": "$isGroup"},
                                  groupName: {"$first": "$groupName"},
                                  createdAt: {"$first": "$createdAt"},
                                  updatedAt: {"$first": "$updatedAt"},
                                  lastMessages: {"$last": "$messages"}
                              }
                          },
                          {$sort: {"lastMessages.createdAt": -1}},
                      ])
                      .exec(function (err, results) {
                          if (err) {
                              console.error(err);
                              return reject(API.error.create('Error aggregate db', 'api', {err}, 1, 6891535665136066));
                          }
      
                          console.log(results);
                          return resolve(results);
                      });
              })
                  .then(threads => {
                      return {
                          threads: threads.map(item => {
                              let recipientIndex = 0;
                              for (let index in item.users) {
                                  if (item.users.hasOwnProperty(index) && item.users[index] && item.users[index].address && item.users[index].address !== sender.publicKey) {
                                      recipientIndex = +index;
                                  }
                              }
                              return {
                                  isGroup: item.isGroup,
                                  groupName: item.groupName,
                                  _id: item._id,
                                  recipientIndex,
                                  users: item.users,
                                  lastMessage: item.lastMessages,
                                  createdAt: item.createdAt,
                                  updatedAt: item.updatedAt,
                              }
                          })
                      }
                  })
          })
          .catch(API.error.validate);

getThreadById
Get my chat info
messenger

  • Information about the method.
    Method name:getThreadById
    Method URL:https://api.inb.ai/api/v1/getThreadById
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    threadIdid chatSTRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/getThreadById
    Send
    Key
    Value
    Description
    threadId
    id chat
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name threadId @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      return new Promise((resolve, reject) => {
          return db.User
              .findById(mongoose.Types.ObjectId(user.user._id), {
                  publicKey: 1,
                  nickname: 1
              })
              .then(sender => {
                  return resolve({sender});
              });
      
      })
      
          .then(({sender}) => {
              return new Promise((resolve, reject) => {
                  db.Thread
                      .aggregate([
                          {
                              $match: {
                                  _id:mongoose.Types.ObjectId(param.threadId),
                                  $and: [{
                                      users: {$elemMatch: {address: sender.publicKey}}
                                  }]
                              }
                          },
                          {
                              $lookup: {
                                  from: "messages",
                                  localField: "_id",
                                  foreignField: "thread",
                                  as: "messages",
                                  // "unwinding" : "$messages",
                              }
                          },
      
                          {$unwind: {path: "$messages"}},
                          {
                              "$group": {
                                  _id: "$_id",
                                  users: {"$first": "$users"},
                                  isGroup: {"$first": "$isGroup"},
                                  groupName: {"$first": "$groupName"},
                                  createdAt: {"$first": "$createdAt"},
                                  updatedAt: {"$first": "$updatedAt"},
                                  lastMessages: {"$last": "$messages"}
                              }
                          },
                          {$sort: {"lastMessages.createdAt": -1}},
                      ])
                      .exec(function (err, results) {
                          if (err) {
                              console.error(err);
                              return reject(API.error.create('Error aggregate db', 'api', {err}, 1, 6891535665136066));
                          }
      
                          console.log(results);
                          return resolve(results);
                      });
              })
                  .then(threads => {
                      if(!threads  || !threads[0]){
                          return Promise.reject(API.error.create('not found', 'api', {}, 1, 9201537098164723));
      
                      }
                      return {
                          thread: threads.map(item => {
                              let recipientIndex = 0;
                              for (let index in item.users) {
                                  if (item.users.hasOwnProperty(index) && item.users[index] && item.users[index].address && item.users[index].address !== sender.publicKey) {
                                      recipientIndex = +index;
                                  }
                              }
                              return {
                                  isGroup: item.isGroup,
                                   groupName: item.groupName,
                                  _id: item._id,
                                  recipientIndex,
                                  users: item.users,
                                  lastMessage: item.lastMessages,
                                  createdAt: item.createdAt,
                                  updatedAt: item.updatedAt,
                              }
                          })[0]
                      }
                  })
          })
          .catch(API.error.validate);

createMessage
Send message
messenger

  • Information about the method.
    Method name:createMessage
    Method URL:https://api.inb.ai/api/v1/createMessage
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    threadIdThread idSTRINGNO
    messageMessageSTRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/createMessage
    Send
    Key
    Value
    Description
    threadId
    Thread id
    message
    Message
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name threadId @type STRING
      @var max=100
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name message @type STRING
      @var max=1000
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      return Promise.resolve()
          .then(() => {
              if (!param.threadId || param.threadId === '' || !mongoose.Types.ObjectId.isValid(param.threadId))
                  return Promise.reject(API.error.create('invalid threadId', 'api', {}, 1, 3301535651618131));
      
              param.threadId = mongoose.Types.ObjectId(param.threadId);
              return db.User
                  .findById(user.user._id, {
                      publicKey: 1,
                      nickname: 1
                  })
                  .then(userDb => {
                      return {userDb};
                  });
          })
          .then(({userDb}) => {
              return db.Thread.findById(param.threadId)
                  .then(thread => {
                      if (!thread || !thread.users) {
                          return Promise.reject(API.error.create('Chat not found', 'api', {}, 1, 4001535651618153));
      
                          // thread not found
                      }
                      let writer = null;
      
                      for (let key in thread.users) {
                          if (thread.users.hasOwnProperty(key) && thread.users[key].address === userDb.publicKey) {
                              writer = thread.users[key];
                              continue;
                          }
      
                      }
                      if (!writer) {
                          return Promise.reject(API.error.create('You are deleted from this chat', 'api', {}, 1, 7341535651614384));
      
                          // error access
                      }
                      if (!writer.accessWrite) {
                          return Promise.reject(API.error.create('You are blocked', 'api', {}, 1, 7511535651610397));
      
                          // you are blocked
                      }
                      return {thread, userDb}
      
                  })
          }).then(({thread, userDb}) => {
              return db.Messages.create({
                  sender: user.user._id,
                  thread: thread._id,
                  message: param.message,
              }).then(message => {
      
                  redis.publishAPI('newMessage', user, {
                      thread,
                      message: {
                          ...message._doc,
                          id: message._id,
                          sender: {address: userDb.publicKey, nickname: userDb.nickname}
                      }
                  });
                  return {
                      ...message._doc,
                      id: message._id,
                      sender: {address: userDb.publicKey, nickname: userDb.nickname}
                  }
              });
          }).catch(API.error.validate);

getMessages
Get messages by id Dialog
messenger

  • Information about the method.
    Method name:getMessages
    Method URL:https://api.inb.ai/api/v1/getMessages
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    threadIdThread idSTRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/getMessages
    Send
    Key
    Value
    Description
    threadId
    Thread id
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name threadId @type STRING
      @var max=100
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      return Promise.resolve()
          .then(() => {
              if (!param.threadId || param.threadId === '' || !mongoose.Types.ObjectId.isValid(param.threadId))
                  return Promise.reject(API.error.create('invalid threadId', 'api', {}, 1, 3301535651618131));
      
              param.threadId = mongoose.Types.ObjectId(param.threadId);
              return db.User
                  .findById(user.user._id, {
                      publicKey: 1,
                      nickname: 1
                  })
                  .then(userDb => {
                      return {userDb};
                  });
          })
          .then(({userDb}) => {
              return new Promise((resolve, reject) => {
                  db.Thread
                      .aggregate([
                          {
                              $match: {
                                  _id: param.threadId,
                                  users: {$elemMatch: {address: userDb.publicKey}}
                              }
                          },
                          {
                              $lookup: {
                                  from: "messages",
                                  localField: "_id",
                                  foreignField: "thread",
                                  as: "messages"
                              }
                          },
      
                          {$unwind: {path: "$messages"}},
      
                          {$sort: {"messages.createdAt": -1}},
      
                          {
                              $lookup: {
                                  from: "users",
                                  localField: "messages.sender",
                                  foreignField: "_id",
                                  as: "messages.sender"
                              },
                          },
                          {
                              $unwind: {path: "$messages.sender"}
                          },
      
                          {$limit: 50},
                          {
                              "$group": {
                                  _id: "$_id",
                                  users: {"$first": "$users"},
                                  isGroup: {"$first": "$isGroup"},
                                  createdAt: {"$first": "$createdAt"},
                                  updatedAt: {"$first": "$updatedAt"},
                                  messages: {
                                      "$push": {
                                          id: '$messages._id',
                                          message: '$messages.message',
                                          attachedUrl: '$messages.attached_url',
                                          attachedType: '$messages.attached_type',
                                          attachedTitle: '$messages.attached_title',
                                          read: '$messages.read',
                                          createdAt: '$messages.createdAt',
                                          updatedAt: '$messages.updatedAt',
                                          sender: {
                                              nickname: '$messages.sender.nickname',
                                              address: '$messages.sender.publicKey'
                                          }
                                      }
                                  }
                              }
                          },
                      ])
                      .exec(function (err, results) {
                          if (err) {
                              console.error(err);
                              return reject(API.error.create('Error aggregate db', 'api', {err}, 1, 6891535665136066));
                          }
                          if (!results || !results[0])
                              return reject(API.error.create('Chat not found', 'api', {err}, 1, 7991535665123392));
      
      
                          return resolve(results[0]);
                      });
              })
      
          }).then(res => {
              console.log(res);
              return res
          })
          .catch(API.error.validate);

messengerContactAdd
Add address to contact
messenger

  • Information about the method.
    Method name:messengerContactAdd
    Method URL:https://api.inb.ai/api/v1/messengerContactAdd
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
    addressaddressSTRINGNO
    nicknamenicknameSTRINGNO
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/messengerContactAdd
    Send
    Key
    Value
    Description
    address
    address
    nickname
    nickname
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code validate param:


      /** @name address @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================
      /** @name nickname @type STRING
      @var max=200
      */ valid(v) { if (!v && v !== '') return {success: false, error: 'Value undefined'}; v = String(v); if (typeof v !== 'string') return {success: false, error: 'Value is not string'}; if (v.length > this.max) return {success: false, error: 'Value length > ' + this.max}; if (this.regexp && !this.regexp.test(v)) return {success: false, error: 'Value not valid regexp'}; return {success: true, value: v}; } // =====================================

    Source code of the method:

      (auth, param) => {
      return db.Contacts
          .findOne({
              user: auth.user._id,
              address: param.address,
          }).then(res => {
              if (res)
                  return Promise.reject(API.error.create('User address already exist', 'api', {}, 1, 6891535645731364));
      
      
              return db.Contacts
                  .create({
                      user: auth.user._id,
                      nickname: param.nickname,
                      address: param.address,
                  })
          })
          .catch(API.error.validate);
      

messengerContactGet
get contacts
messenger

  • Information about the method.
    Method name:messengerContactGet
    Method URL:https://api.inb.ai/api/v1/messengerContactGet
    Access level:Private API (User access)
    Тип:all


    POST PARAMETERS

    NameDescriptionTypeRequiredDefault value
  • Response

    NameDescriptionTypeDefault value
    successStatus request methodtrue, false
    errorError data.(exists only in cases of error){message,error_type,level,stack}
    dataResult data.{}
    latency_msprocessing time of the request (milliseconds)78
  • POST
    https://api.inb.ai/api/v1/messengerContactGet
    Send
    Key
    Value
    Description
    • Status:wait
    • Time:0 ms
    • Click send.
    • Click send.
    • Click send.
  • Source code of the method:

      (auth, param) => {
      return db.Contacts
          .find({
              user: auth.user._id
          })
          .then(contacts => ({contacts}))
          .catch(API.error.validate);