NEM Twitter tip bot websocket API reference

この tipbot のもう一つの特徴としてAPI経由で全ての操作を行えることが挙げられます。 このAPIを使用したサイトの例として NEMbookが挙げられます。 tipbot により承認を受けたサイトにはアクセスキーが登録され、上位のアクセス権限が付与されます。

コマンド形式

コマンド一覧

ユーザー権限

websocket にアクセスするユーザーには権限が与えられます。

 level 0 : guest
 level 1 : login user
 level 2 : login user (Enhanced)
 level 3 : contents provider
 level 4 : contents provider (Enhanced)
 level 255 : admin

request

request データ形式

送信データ
{
   "command": COMMAND NAME,
   "data": DATA,
   "uuid": UNIQUE_ID
}
受信データ
{
   "command": COMMAND NAME,
   "type": "request",
   "time": UNIX TIMESTAMP,
   "spent_msec": X (msec),
   "data": DATA,
   "uuid": UNIQUE_ID,
   "result": True or False
}
コネクション時データ
{
   "level": 0,
   "user_code": "ddf8b984fdba0d878b64afbbd1bc26d38f32096767825889e0b94481f5f0ef8b",
   "screen": null,
   "tag": null,
   "time": 1504172328
}

request コマンド bot

COMMAND NAME need level
bot/info 0
bot/stop 255
bot/debug 0

bot/info

response

{
   "net": "testnet",
   "height": 1090647,
   "address": "TA7CKYFLAKGE26BWROOI3TCCR27MSFWSVUA66D5J",
   "uptime": 2212,
   "ws_user": 2,
   "thread": [
      "MainThread", "streaming", "incomimg", "ws_ticker", "ws_server",
      "analyze", "price", "lottery"
   ],
   "version": "1.2.dev"
}

bot/stop

response

{
  "status": true
}

bot/debug

respnse

true

request コマンド user

COMMAND NAME need level
user/info 0
user/offer 0
user/check 0
user/upgrade 1
user/pubkey/setup 2
user/pubkey/login 0
user/oauth/setup 2
user/oauth/verify 0
user/shortcut 1
user/shortcut/push 1
user/shortcut/delete 1

user/info

request は空文字です。

response

{
   "screen_name": "@example_user",
   "level": 1,
   "user_code": "08ccaee2e4a917b781d9b48ee8a927ff197ead224f65f43c3dd445a9785aac7a",
   "tag": "1234567abc",
   "debug": false,
   "login_time": 1509022077,
   "importance": 0.123563
}

user/offer

request

{
  "screen_name": "@request_user"
}

response

{
   "screen_name": "@request_user",
   "send_pin": true
}

user/check

request

{
  "screen_name": "@request_user",
  "pincode": 48327
}

response

{
  "screen_name": "@request_user",
   "level": 1
}

user/upgrade

request

{
  "require_level": 2
}

response

{
   "send_pin": true
}

※コンテンツプロバイダーが認証する場合
unixtime を16進数(0x599800b9)+pubkey のバイナリを prikey で署名します。
ですので、0x599800b90cda844db921f4bdf58eb8e9c2741e56194b9890e956bb39a68bbbd100cc4cd0 の署名になります。
検証が行われると即 require_level に変更されPIN認証は不要です。署名アルゴリズムはNEMのものと同じです。
time はサーバー受信時の時間と5分以上差があってはいけません

request

{
  "require_level": 5,
  "time": 1503133881,
  "pubkey" : "0cda844db921f4bdf58eb8e9c2741e56194b9890e956bb39a68bbbd100cc4cd0",
  "sign": "a9c9c938efe78c244261a920f032a803f361561a862722ccdc2d07b98e542e3c823883169391a842dcef80bf24eeca5e4c1ed2122a59d7e3f486bf3d70d75903"
}

response

{
   "send_pin": false
}

user/pubkey/setup

request

{
   "pubkey": "7f59e2388d5c472b4fc60d78a0bcb59c60180f2d7cd3ba4c8cfa365d542adb7d",
   "level": 1
}

response

{"level": 1}

user/pubkey/login

request

{
   "screen_name": "@example_name",
   "sign": "73de51fdc0e4280a86800efb465........fe3ae0cb6354405022689a5b1d4"
}

response

{"level": 1}

user/oauth/setup

response

{"redirect_url": "https://api.twitter.com/oauth/authorize?oauth_token=4LUDBODNDI4453oOINOIN"}

user/oauth/verify

request

{
  "oauth_token": "4LUDBODNDI4453oOINOIN",
  "oauth_verifier": "KFEJS35iOJWODMO"
}

response

{
  "result": true
}

user/shortcut

request

{
  "user": true,
  "global": true
}

response

[
   {
      "uuid": 32,
      "user": "@user_id",
      "original_name": "namuyan:nemurin",
      "short_name": "nemrin",
      "time": 1501665000
   },
   {
      "uuid": 21,
      "user": "@user_id",
      "original_name": "gox:gox",
      "short_name": "GOX",
      "time": 1501325000
   },
   {
      "uuid": 2,
      "user": "global",
      "original_name": "nem:xem",
      "short_name": "XEM",
      "time": 1501000000
   }
]

user/shortcut/push

request

{
  "original_name": "namuyan:nemurin",
  "short_name": "nemrin",
  "type": "user"
}

response

{
  "uuid": 32
}

user/shortcut/delete

request

{
  "uuid": 32
}

respose

{
  "result": true
}

request コマンド account

COMMAND NAME need level
account/balance 1
account/balance/unconfirmed 1
account/history 1
account/history/check 1
account/history/delete 1
account/throw 2
account/lottery/setup 2

account/balance

response

{
   "all": {
      "nem:xem": 10000000
   },
   "network": {
      "nem:xem": 10000000
   },
   "tip": {
      "nem:xem": 0
   }
}

account/balance/unconfirmed

response

{
   "network": {
      "cxaxa:xaxzdddsssssssssssssssssssssssss": 12,
      "nem:xem": 10000000
   },
   "tip": {
      "nem:xem": 0
   }
}

account/history

request (@your_id => @recipient_id)

{
  "uuid": 34567,
  "sender": "@sender_id",
  "recipient": "@recipient_id"
}

response

[
   {
      "uuid": 12345,
      "sender": "@sender_id",
      "recipient": "@your_id",
      "mosaic_name": "nem:xem",
      "amount": 1000000,
      "time": 1503124526300,
      "twitter": {
         "original": {
            "id": 797778180102754325,
            "id_str": "797778180102754325",
            "text": "投げ銭下さい、何でもしますから"
         },
         "tip": {
            "id": 797778180102754330,
            "id_str": "797778180102754330",
            "text": "@tipnem tip @recipient 1 nem 今なんでもって"
         },
         "reply": {
            "id": 797778180102754351,
            "id_str": "797778180102754351",
            "text": "@tipnem @recipient ナンデモスルトハイッテイナイ"
         }
      },
      "checked": true
   },
   {
      "uuid": 12342,
      "sender": "@sender_id",
      "recipient": "@your_id",
      "mosaic_name": "namuyan:nemrin",
      "amount": 36,
      "time": 1503124526220,
      "twitter": {
         "original": {
            "id": 797778180102754300,
            "id_str": "797778180102754300",
            "text": "投げられた"
         },
         "tip": {
            "id": 797778180102754312,
            "id_str": "797778180102754312",
            "text": "@tipnem tip @recipient 36 nemurin 投げたがリプが無い時"
         },
         "reply": {}
      },
      "checked": true
   },
   {
      "uuid": 12340,
      "sender": "@your_id",
      "recipient": "@recipient_id",
      "mosaic_name": "nem:xem",
      "amount": 100000,
      "time": 1503124526110,
      "twitter": {
         "original": {},
         "tip": {
            "id": 797778180102754289,
            "id_str": "797778180102754289",
            "text": "@tipnem tip @recipient 0.1 nem 唐突に投げた、リプも無い、チェックもされていない"
         },
         "reply": {}
      },
      "checked": false
   },
   {
      "uuid": 12339,
      "sender": "@your_id",
      "recipient": "@recipient_id",
      "mosaic_name": "nem:xem",
      "amount": 100000,
      "time": 1503124526001,
      "twitter": {
         "original": {},
         "tip": {
            "id": null,
            "id_str": null,
            "text": "account/throwコマンドを使用して送ります、アナウンスしていません"
         },
         "reply": {}
      },
      "checked": false
   }
]

account/history/check

request

{
  "uuid": 12342
}

response

{
  "uuid": 12342
}

account/history/delete

request

{
  "uuid": 12340
}

response

{
  "uuid": 12340
}

account/throw

request

{
   "sender": "@sender",
   "recipient": "@recipient",
   "mosaic": "nem:xem",
   "amount": 1000000,
   "text": "1XEMを送ります",
   "announce": true
}

response

{
  "uuid": 23456
}

account/lottery/setup

request

{
   "distribute_order": {
      "simple_fake_check": true,
      "simple_fake_check_min": 15,
      "deep_fake_check": true,
      "deep_fake_check_score_min": -2,
      "deep_fake_check_score_max": 2,
      "my_follower": true,
      "prize": [
         ["nem:xem", 5000000, 6],
         ["nem:xem", 1000000, 6],
         ["nem:xem", 1000000, 6],
         ["sample:mosaic", 120, 2]
      ]
   },
   "original_id": 913763726913761281,
   "finish_time": 1234567890
}

response

{"uuid": 1234}

account/lottery/status

request

{"uuid": 1234}

response

[
   {
      "uuid": 7,
      "screen": "@user_name",
      "url": "https://twitter.com/user_name/status/1234567890123",
      "distribute_order": {
         "simple_fake_check": false,
         "simple_fake_check_min": 15,
         "deep_fake_check": false,
         "deep_fake_check_score_min": -2,
         "deep_fake_check_score_max": 2,
         "my_follower": false,
         "prize": [
            ["nem:xem",5000000,6],
            ["nem:xem",1000000,6],
            ["nem:xem",1000000,6],
            ["namutest:c0ban",2,0]
         ]
      },
      "retweet": [
         "123456789012345567",
         "345678901234567890",
         "7654321098",
         "6543123456"
      ],
      "distribution": null,
      "start": 1507964344,
      "finish": 1507971600,
      "finished": 2
   }
]

request コマンド nem

COMMAND NAME need level
nem/history 1
nem/gettag 1
nem/send 2
nem/send/estimate 1
nem/lost 1
nem/mosaic/status 0
nem/mosaic/img 0
nem/mosaic/update 1

nem/history

request

{
  "uuid": 4532,
  "type": 0
}

type=0 outgoing response

[
   {
      "uuid": 26,
      "type": "outgoing",
      "txhash": "ea105b4bda572a9bd4f916985c69f65011e3cbfab2bcf38b7398bd33c05a5d40",
      "sender": "@sender_id",
      "recipient": "TDEK3DOKN54XWEVUNXJOLWDJMYEF2G7HPK2LRU5W",
      "message": "check15",
      "mosaics": {
         "nem:xem": 1050000
      },
      "height": 1088468,
      "utime": 1503593300
   },
   {
      "uuid": 14,
      "type": "outgoing",
      "txhash": "907d373a4af9265d0fc36ef7bc2f8d42a25bff6b72cd2a091a0ae7ee8341dcb7",
      "sender": "@sender_id",
      "recipient": "TDEK3DOKN54XWEVUNXJOLWDJMYEF2G7HPK2LRU5W",
      "message": "check10",
      "mosaics": {
         "nem:xem": 1050000
      },
      "height": 1088428,
      "utime": 1503591181
   }
]

type=1 incoming response

[
   {
      "uuid": 17,
      "type": "incoming",
      "txhash": "cd5585eda8351fa43ae44cc54a2cf7321597de48505d5d912c88c3a76582924e",
      "sender": "TDEK3DOKN54XWEVUNXJOLWDJMYEF2G7HPK2LRU5W",
      "recipient": "@recipient_id",
      "message": "3b49dfaf51 入金",
      "mosaics": {
         "nem:xem": 10000000
      },
      "height": 1087678,
      "utime": 1503545925
   },
   {
      "uuid": 23,
      "type": "incoming",
      "txhash": "d7277c02176b2739ab8327ea14ad65b44e40742b28875c3698964f632bd82e56",
      "sender": "TDEK3DOKN54XWEVUNXJOLWDJMYEF2G7HPK2LRU5W",
      "recipient": "@recipient_id",
      "message": "3b49dfaf51 送ります☺",
      "mosaics": {
         "cxaxa:xaxzdddsssssssssssssssssssssssss": 12,
         "nem:xem": 10000000
      },
      "height": 1093298,
      "utime": 1503885857
   }
]

nem/get_tag

request は空文字

response

{
  "tag": "168ab36f4a"
}

nem/send

request

{
   "sender": "@sender_id",
   "recipient": "TALICE6KJ2SRSIJFVVFFH6ICUIYZ2ZZGNFUDJGRT",
   "mosaics": {
      "nem:xem": 1000000,
      "valu:youtuber": 37564
   },
   "message": "send mosaics"
}

response

{
  "txhash": "83e594edad2579de5ac338c5cef5aa5ea3ca46c4c78518a49e04c6528358d836"
}

nem/send/estimate

request

{
   "sender": "@sender_id",
   "recipient": "TALICE6KJ2SRSIJFVVFFH6ICUIYZ2ZZGNFUDJGRT",
   "mosaics": {
      "nem:xem": 1000000,
      "valu:youtuber": 37564
   },
   "message": "send mosaics"
}

response

{
   "all": {
      "nem:xem": 300000,
      "valu:youtuber": 37564,
      "levy:mosaic": 10
   },
   "fee": {
      "send": {
         "nem:xem": 50000
      },
      "levy": {
         "nem:xem": 0,
         "levy:mosaic": 10
      },
      "msg": {
         "nem:xem": 50000
      }
   },
   "result": true
}

nem/lost

request

{
  "txhash": "dfa875cad4888b0a3aed7b12674a8b195363a2bef51faf3358ea3da1133c249c",
  "sign": "38054c1f7d03f36ae6a1b737eb9300421c.......d2280f4cb234daf6dfecf5025e18399d7",
  "pubkey": "a8016c58439a21ad1f164c223297a2c4e97c1d64c3d8d3a19bef042d5a35c531"
}

response

{"uuid": 1234}

nem/mosaic/status

request

[
  "namuyan:nemurin", "valu:youtuber", "error:error"
]

response

{
   "namuyan:nemurin": {
      "creator": "TB235JLAOGALDATDJC7LXDMZSDMFBUMDVIBFVQPF",
      "description": "NEMRIN",
      "image": {
         "register": "@namuyan_mine",
         "type": 0,
         "url": "http://imgur.com/aPrj123.png"
      },
      "properties": {
         "divisibility": 0,
         "initialSupply": 0,
         "supplyMutable": true,
         "transferable": true
      },
      "levy": {
         "fee": 100000000,
         "recipient": "TB235JLAOGALDATDJC7LXDMZSDMFBUMDVIBFVQPF",
         "type": 2,
         "mosaic": "nem:xem"
      }
   },
   "valu:youtuber": {
      "creator": "TB235JLAOGALDATDJC7LXDMZSDMFBUMDVIBFVQPF",
      "description": "test",
      "image": {
         "register": null,
         "type": 0,
         "url": "http://imgur.com/aPrj123.png"
      },
      "properties": {
         "divisibility": 0,
         "initialSupply": 0,
         "supplyMutable": true,
         "transferable": true
      },
      "levy": {}
   },
   "error:error": null
}

nem/mosaic/img

request

[
  "namuyan:nemurin", "valu:youtuber", "error:error"
]

response

{
   "namuyan:nemurin": "http://i.imgur.com/h9SmLUb.png",
   "valu:youtuber": "http://i.imgur.com/9ZuJwTs.png",
   "error:error": "http://i.imgur.com/9ZuJwTs.png"
}

nem/mosaic/update

request

{
   "mosaic_name": "namuyan:nemurin",
   "mosaic_url": "http://example.com/iamge.png",
   "type": 1
}

response

{
  "mosaic_name": "namuyan:nemurin"
}

price コマンド price

COMMAND NAME need level
price/all 0

price/all

response

{
   "xem_jpy": [23, true],
   "mona_jpy": [385.6, false],
   "btc_jpy": [632372.5, true],
   "eth_jpy": [34100, true]
}

shop コマンド shop

COMMAND NAME need level
shop/item 0
shop/item/search 0
shop/seller/setup 2
shop/seller/edit 2
shop/buyer/good 1
shop/buyer/buy 2

NEMERとNEMERを繋げる簡易ショップ

shop/item

shop/item/search

request

{
  "like": "寿司",
  "index": 0
}

response

[
   {
      "uuid": 1,
      "image": "https://i.imgur.com/uOQw7hR.jpg",
      "good": 0,
      "seller": "@namuyan_mine",
      "mosaic": "XEM",
      "amount": 1000000,
      "divisibility": 6,
      "title": "お寿司の詰め合わせ",
      "article_index": "詰め合わせ,お寿司,テスト用",
      "creation_time": 1509696523,
      "finish_time": 1510041600
   },
   {
      "次の": "ショップ"
   }
]

shop/seller/setup

request

{
   "image": "https://i.imgur.com/uOQw7hR.jpg",
   "title": "お寿司の詰め合わせ",
   "article": "こちらお寿司の詰め合わせになります。\nテスト用です。[img]https://i.imgur.com/uOQw7hR.jpg[/img]",
   "mosaic": "nem:xem",
   "amount": 1000000,
   "number": 3,
   "finish_time": "1510041600"
}

response

{"uuid": 123}

shop/seller/edit

request

{
   "uuid": 1,
   "target": "number",
   "content": -1
}

response

{ "uuid": 1 }

shop/buyer/good

request

{ "uuid": 1 }

response

{ "uuid": 1 }

shop/buyer/buy

streaming コマンド一覧

streaming

コマンド一覧

COMMAND NAME need level
nis/block 0
nis/incoming 1
tip/receive 1

streamingデータ形式

受信データ
{
   "command": COMMAND NAME,
   "type": "streaming",
   "time": UNIX TIMESTAMP,
   "data": DATA,
   "result": True or False
}

nis/block

{
   "height": 1082147,
   "time": 1575623518,
   "type": 1,
   "signer": "TA7CKYFLAKGE26BWROOI3TCCR27MSFWSVUA66D5J"
}

nis/incoming

{
   "height": 1095535,
   "txhash": "19d9f21e3d3e2d0dd84d1c080cbdf5b613af3b936ed6923a77f1326bb29f0e23",
   "screen_name": "@namuyan_mine",
   "sender": "TDTM7NAX3EZ2KD3O22SBRMLFREYWHPTW2GXTSL5W",
   "mosaics": {
      "nem:xem": 98000000
   },
   "fee": 2000000,
   "message": "3b49dfaf51 テスト",
   "message_type": 1,
   "time": 1504020708
}

tip/receive

{
   "uuid": 123,
   "sender": "@sender_id",
   "recipient": "@recipient_id",
   "mosaic": "nem:xem",
   "amount": 7974000,
   "original_txt": "暴落ニャニャニャ(痙攣",
   "tip_txt": "餌だぞホラ",
   "time": 1504021227
}

RETURN