Stemmit mention tool -- update the bot framework and use a formal wechat account
utopian-io·@cha0s0000·
0.000 HBDStemmit mention tool -- update the bot framework and use a formal wechat account
# 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.  --- ## 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. <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@cha0s0000/stemmit-mention-tool-update-the-bot-framework-and-use-a-formal-wechat-account">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>