如何使用Steem API/transfer-history和IFTTT同步到Slack消息?


上回的帖子里,我介绍了一API,但是很多人不清楚如何使用,或者说,到底能拿来干啥.今天我就介绍一个小应用.

我们公司用的内部聊天软件是SLACK,这玩意可以开放API给第三方,可以整合很多其它工具,特别是可以用IFTTT (If This Then That) 来连接其它的工具.

比如,我就想,如果别人给我帐号里送钱了,我想第一时间知道,而不是时不时的去刷 steemit.com 的钱包页面.我想这个消息能自动的推送到我公司用的聊天工具 Slack 上.

怎么用?很简单,首先你需要在你的机器(可以是服务器)上创建一个脚本,比如PHP脚本 (假设文件名为 check-transfer-history.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
// https://justyy.com/archives/5072
$id = 'justyy';
$tx = json_decode(file_get_contents("https://uploadbeta.com/api/steemit/transfer-history/?id=" . $id), true);
foreach ($tx as $r) {
  $t =  $r['time'];
  $desc = $r['time_desc'];
  $memo = $r['memo'];
  $tx = $r['transaction'];
  if (preg_match('/(\d)+\s+(second|minute|hour)s? ago/i', $desc, $matches)) {
    if (
          ($matches[2] == 'second') || 
          (($matches[2] == 'minute') && ($matches[1] == '1'))
    ) { // 这里只捕获2分钟内的消息 可以根据你的需求更改
      $cmd = 'curl -s -X POST -H "Content-Type: application/json" -d \'{"value1":"'.$desc.'","value2":"'.$tx.'","value3":"'.$memo.'"}\' https://maker.ifttt.com/trigger/{steemit_transfer}/with/key/YOUR_APP_KEY';
      echo $cmd;
      shell_exec($cmd);             
    }    
  } else {
    break;
  }
}
<?php
// https://justyy.com/archives/5072
$id = 'justyy';
$tx = json_decode(file_get_contents("https://uploadbeta.com/api/steemit/transfer-history/?id=" . $id), true);
foreach ($tx as $r) {
  $t =  $r['time'];
  $desc = $r['time_desc'];
  $memo = $r['memo'];
  $tx = $r['transaction'];
  if (preg_match('/(\d)+\s+(second|minute|hour)s? ago/i', $desc, $matches)) {
    if (
          ($matches[2] == 'second') || 
          (($matches[2] == 'minute') && ($matches[1] == '1'))
    ) { // 这里只捕获2分钟内的消息 可以根据你的需求更改
      $cmd = 'curl -s -X POST -H "Content-Type: application/json" -d \'{"value1":"'.$desc.'","value2":"'.$tx.'","value3":"'.$memo.'"}\' https://maker.ifttt.com/trigger/{steemit_transfer}/with/key/YOUR_APP_KEY';
      echo $cmd;
      shell_exec($cmd);             
    }    
  } else {
    break;
  }
}

这里需要替换的是第一行你的STEEM ID 和 你的 YOUR_APP_KEY, 这个值是 IFTTT 里的 Web Request 频道. 然后 接下来你需要 在 IFTTT里添加应用 Slack , 并且创建一个规则:

ifttt-configure 如何使用Steem API/transfer-history和IFTTT同步到Slack消息? I.T. IFTTT SteemIt

ifttt-configure

可以看到,我们可以传入3个值,那么就可以根据 steemit/transfer-history 提供的时间,事件和MEMO依次定制这些消息.

然后我们需要把上面那个PHP脚本 添加到 crontab 里 crontab -e 这里2分钟运行脚本进行检查,2分钟和上面PHP脚本里是对应的.

*/2 * * * * php /path/to/check-transfer-history.php   

然后呢,我们试验一下, 我试着给我媳妇 @happyukgo 发了钱 0.001 SBD

send-message 如何使用Steem API/transfer-history和IFTTT同步到Slack消息? I.T. IFTTT SteemIt

send-message

然后 2分钟内就收到了Slack消息的推送:

slack-receive-messages-via-ifttt 如何使用Steem API/transfer-history和IFTTT同步到Slack消息? I.T. IFTTT SteemIt

slack-receive-messages-via-ifttt

英文: How to Use Steem API/transfer-history and IFTTT to sync to Slack?

GD Star Rating
loading...
本文一共 372 个汉字, 你数一下对不对.
如何使用Steem API/transfer-history和IFTTT同步到Slack消息?. (AMP 移动加速版本)
上一篇: SteemIt API/transfer-history 最简单获取帐号钱包记录的API
下一篇: SteemIt 怎么样点赞收益最高? (新老用户都来看看)

扫描二维码,分享本文到微信朋友圈
1a49a52cd407a7d426549cc7df19dce6 如何使用Steem API/transfer-history和IFTTT同步到Slack消息? I.T. IFTTT SteemIt

评论