Stemmit mention tool -- update the bot framework and use a formal wechat account

in #utopian-io7 years ago (edited)

New features


What feature(s) did you add?

  • Mention when get the comment

  • Use Workerman framework to get the related data ,which is convenient for extending in the future

  • Use Wechat public account instead of the Wechat private account.That can become more and more expansible .As we all know ,wechat private account may be prohibited using as bot.So choose the Wechat public account is necessary.

    GIF.gif


How did you implement it/them?

  • SteemitWechatBot/V0.2/Python bot/main.py
def worker(start, end):
    global s, b,send_to_workerman
    print('start from {start} to {end}'.format(start=start, end=end))
    block_infos = s.get_blocks(range(start, end+1))
    # print(block_infos)
    for block_info in block_infos:
        transactions = block_info['transactions']
        for trans in transactions:
            operations = trans['operations']
            for op in operations:
               if op[0] == 'comment' and op[1]['parent_author'] == 'cha0s0000':
                    postdata = json.dumps(op[1])
                    send_to_workerman=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                    send_to_workerman.connect(('192.168.2.1',8282)) 
                    send_to_workerman.send(postdata.encode('utf-8'))
send_to_workerman.close()

Import steempython to get the block data from steemit every three seconds.When get some new comment about my Steemit name then send the detail data to TCP server

  • SteemitWechatBot/V0.2/Workerman TCP Server/Applications/YourApp/Events.php
   public static function onMessage($client_id, $message)
   {
        $message_type = substr($message,0,2);
        $data = json_decode($message,true);
        $link = $data['parent_permlink'];
        $parent_author = $data['parent_author'];
        $author = $data['author'];
        $body = $data['body'];
        $link = 'https://steemit.com/@'.$parent_author.'/'.$link;
        $appid = 'wx63d349787679880a';
        $appsec = '197d9698db455bc1e71dbe8793b15ea0';  
        $token_url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsec;
        $json_token = http_request($token_url);
        $tokendata=json_decode($json_token,true);
        $access_token = $tokendata['access_token'];
        $template=array(          
          'touser'=>"o6zvTwIbhFW7PIPEhvSJZKKq_CGg",
          'template_id'=>"iwfI1ywCN6CCk5XiU5otISVZrADu9wRKoOyjEElj0PE",
          'url'=>$link,
          'topcolor'=>"#7B68EE",
          'data'=>array(
                  'first'=>array('value'=>urlencode("New comment"),'color'=>"#FF0000"),
                  'author'=>array('value'=>urlencode($author),'color'=>'#173177'),
                  'link'=>array('value'=>urlencode($link),'color'=>'#173177'),
                  'remark'=>array('value'=>urlencode($body),'color'=>'#173177'), )
          );
        $json_template=json_encode($template);
        //echo $json_template;
        //echo $this->access_token;
        $url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
        $res=http_request($url,urldecode($json_template));
        GateWay::sendToAll($res);
        
       
   }

Create my mention template in the Wechat public account setting before, then get the template ID and the information format of the template.

Receive the detail data from python script and get the comment author and permlink then send to the user as the template.


Roadmap

  • Add all types of mention
  • Register a formal Wechat public service account to replace my testing account.
  • Build up a front end web UI to record the user,which can lead to automatic operation from front to end.

How to contribute?

Github: https://github.com/Cha0s0000/SteemitWechatBot

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Congratulations @cha0s0000! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.

To support your work, I also upvoted your post!
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @cha0s0000 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.029
BTC 62228.71
ETH 2419.51
USDT 1.00
SBD 2.57