http://technologyworkroom.blogspot.sg/2013/05/tasker-how-to-read-out-whatsapp.html

Tasker can read out incoming or stored WhatsApp Messages, I used Tasker to do the following things on WhatsApp:

  • Display the incoming messages in iOS style, no need to pull down the notification menu to read the messages. The whole message is displayed in the menu bar. See screenshot for details
  • Play different notification sounds for different contacts or different message content, this way you can for example get a special notification if your name is mentioned.
  • Mute WhatsApp at specific times or at specific locations, without muting other notifications.
  • Update: Read aloud WhatsApp messages

What we need:

  • Tasker
  • WhatsApp
  • root. I want you to root your phone now! You need root for SQLite, we need it to read out the database of WhatsApp.
  • SQLite for Android
  • Kyo-Tux Aeon HD icon pack, provides useful icons for Tasker, its free and lightweight, so grab it

Here is the complete profile:

Profile: WhatsApp Statusbar
Priority: 9 CoolDown: 0
Event: Notification [ Owner Application:WhatsApp Title:* ] Enter: WhatsApp Notification
Run Both Together
A1: Run Shell [ Command:sqlite3 /data/data/com.whatsapp/databases/msgstore.db "SELECT timestamp,data,key_remote_jid FROM messages WHERE key_from_me='0' ORDER BY timestamp DESC LIMIT 1;" Timeout (Seconds):15 Use Root:On Store Result In:%sql_result Continue Task After Error:On ]
A2: If [ %sql_result !~ %SQL_RESULT_OLD ]
A3: Variable Set [ Name:%SQL_RESULT_OLD To:%sql_result Do Maths:Off Append:Off ]
A4: Variable Split [ Name:%sql_result Splitter:| Delete Base:On ]
A5: Variable Set [ Name:%sql_result1 To:%sql_result1/1000 Do Maths:On Append:Off ]
A6: Variable Convert [ Name:%sql_result1 Function:Seconds to Date Time Store Result In: ]
A7: Variable Split [ Name:%sql_result1 Splitter: Delete Base:Off ]
A8: Variable Search Replace [ Variable:%sql_result12 Search:\. Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With:: ]
A9: Perform Task [ Name:Number->Name WhatsApp Stop:Off Priority:6 Parameter 1 (%par1):%sql_result3 Parameter 2 (%par2): Return Value Variable:%sql_result3 ]
A10: Wait Until [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ] If [ %sql_result3 !~R @s.whatsapp.net ]
A11: Array Push [ Name:%WHATSAPP_NOTIFY Position:1 Value:%sql_result3: %sql_result2 Fill Spaces:Off ]
A12: Notify Cancel [ Title:%WHATSAPP_NOTIFY4 Warn Not Exist:Off ]
A13: Variable Clear [ Name:%WHATSAPP_NOTIFY4 Pattern Matching:Off ]
A14: Notify [ Title:%sql_result3: %sql_result2 Text:%sql_result2 Icon:ipack:kyotuxaeonhd:buddy_green Number:0 Permanent:Off Priority:3 ]
A15: Perform Task [ Name:Play Sound Stop:Off Priority:6 Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: ]
A16: End If

The most important line is A1. Here we use the installed sqlite to save the time, the sender and the content of the last message stored in the WhatsApp database into a Tasker variable. The values are separated by a "|", the time is in ms and the sender is stored as a phone numer. So there are some conversions needed afterwards.
You may have noticed that there is a call to another task at line A9. WhatsApp saves only the number of the contact who send you the message in its database, so we need to convert the number to a real contact name as saved in your phone book. The task "Number->Name WhatsApp" does it. It searches the address book for contacts associated with a WhatsApp account and returns their name. So after line A10 you should know who texted you by name, you can put in if clauses to react different to different names. Here the description of the "Number->Name WhatsApp" task:

Number->Name WhatsApp
A1: Run Shell [ Command:sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db "SELECT display_name FROM raw_contacts WHERE sync1 like '%par1';" Timeout (Seconds):5 Use Root:On Store Result In:%sql_result_name Continue Task After Error:On ]
A2: If [ %sql_result_name !~R sql_result_name ]
A3: Return [ Value:%sql_result_name Stop:On ]
A4: Else
A5: Return [ Value:%par1 Stop:On ]
A6: End If

At line A15 of the task "WhatsApp Notification" task I call a Tasker task called "Play Sound". That's because I disabled notification sounds in WhatsApp to handle them myself (They are time and WhatsApp message content depandant). Here an example of how a simple "Play Sound" task could look like:

Play Sound
Run Both Together
A1: If [ %par1 ~R .*[Rr]+[Uu]+[Aa]+[Rr]+.* ]
A2: Variable Set [ Name:%tmp To:%VOLS Do Maths:Off Append:Off ]
A3: Wait [ MS:50 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A4: System Volume [ Level:7 Display:Off Sound:Off ]
A5: If [ %SILENT ~ off ]
A6: Play Ringtone [ Type:Notification Sound:Dinosaur Roar Stream:1 ]
A7: Else If [ %HEADSET ~ 1 ]
A8: Play Ringtone [ Type:Notification Sound:Dinosaur Roar Stream:1 ]
A9: End If
A10: Vibrate [ Time:1000 ]
A11: Vibrate [ Time:1000 ]
A12: Vibrate [ Time:1000 ]
A13: Vibrate [ Time:1000 ]
A14: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
A15: System Volume [ Level:%tmp Display:Off Sound:Off ]
A16: Else If [ %par1 ~R [Mm][Ii][Aa][Uu]+\b ]
A17: If [ %SILENT ~ off ]
A18: Play Ringtone [ Type:Notification Sound:Miau Stream:1 ]
A19: Else If [ %HEADSET ~ 1 ]
A20: Play Ringtone [ Type:Notification Sound:Miau Stream:1 ]
A21: End If
A22: Else
A23: If [ %par2 !~ 1 ]
A24: If [ %HEADSET !~ 1 ]
A25: If [ %SILENT ~ off ]
A26: Vibrate [ Time:100 ]
A27: Play Ringtone [ Type:Notification Sound:Good news Stream:5 ]
A28: End If
A29: End If
A30: End If
A31: End If

If headphones are connected or phone is on silent mode no sound is played at all. If the message contains something like "Rrruaaarrrr" a dinosaur roar is played at full volume (even with headphones connected) and the phone vibrates for 4 seconds. If a "Miauuu" is in the message a cats miau is played... I'm sure you can do better :)

You can even make Tasker react on a click on one of the notifications, just add the following profile:

Profile: WhatsApp Notification1 Click
Event: Notification Click [ Owner Application:Tasker Title:%WHATSAPP_NOTIFY1 ]
Enter: Open WhatsApp
A1: Load App [ App:WhatsApp Data: Exclude From Recent Apps:Off ]

Duplicate this profile two times so you can click on any of our three custom notifications.

Profile: WhatsApp Notification2 Click
Event: Notification Click [ Owner Application:Tasker Title:%WHATSAPP_NOTIFY2 ]
Enter: Open WhatsApp
A1: Load App [ App:WhatsApp Data: Exclude From Recent Apps:Off ] Profile: WhatsApp Notification3 Click
Event: Notification Click [ Owner Application:Tasker Title:%WHATSAPP_NOTIFY3 ]
Enter: Open WhatsApp
A1: Load App [ App:WhatsApp Data: Exclude From Recent Apps:Off ]

I added another profile which deletes all our custom made WhatsApp notifications automatically after opening WhatsApp. Looks like this:

Profile: WhatsApp opened
Application: WhatsApp Enter: WhatsApp Notification clear
A1: Notify Cancel [ Title:%WHATSAPP_NOTIFY1 Warn Not Exist:Off ]
A2: Notify Cancel [ Title:%WHATSAPP_NOTIFY2 Warn Not Exist:Off ]
A3: Notify Cancel [ Title:%WHATSAPP_NOTIFY3 Warn Not Exist:Off ]
A4: Variable Clear [ Name:%WHATSAPP_NOTIFY* Pattern Matching:On ]
A5: Stop [ With Error:Off Task:WhatsApp Notification ]

Have fun and use this knowledge wisely. Please leave your thoughts in the comments, I'm very excited about your implementations. Hope you read this Ruy Aguilar ;)

cv

How to read out WhatsApp messages with Tasker and react on their content in real time的更多相关文章

  1. Send a WhatsApp Message programatically -- Tasker WhatsTasker

    Here is My code snippet: Uri mUri = Uri.parse("smsto:+9876543210"); Intent mIntent = new I ...

  2. Solution for sending Whatsapp via sqlite "INSERT INTO"

    I use something similar but thought I'd mention this 'bug' that can happen:when you INSERT '%wa_mess ...

  3. Ultimate Guide to WhatsApp for Business 2019

    By Iaroslav Kudritskiy (Source: https://rocketbots.io/blog/the-ultimate-guide-to-whatsapp-business-a ...

  4. 免费好用的 Apple 工具(Windows 适用)

    首先,下载链接: https://pan.baidu.com/s/1Sfx3SB8Ya1aMS01aXk--rA 密码: 6y69 1. Airplay (itools) : ios 可以投屏到win ...

  5. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  6. Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理5

    我们先直接拷贝下blank.html这个页面的代码,顺带先建立一个Home控制器,并添加Index视图.将代码拷贝进去. <!DOCTYPE html> <html lang=&qu ...

  7. Android之数据库的创建

    一.SQLite介绍 SQLite 一个非常流行的嵌入式数据库,它支持 SQL 语言,并且只利用很少的内存就有很好的性能.此外它还是开源的,任何人都可以使用它.许多开源项目((Mozilla, PHP ...

  8. Asp.Net MVC中使用ACE模板之Jqgrid

    第一次看到ACE模板,有种感动,有种相见恨晚的感觉,于是迅速来研究.它本身是基于bootstrap和jqueryui,但更nice,整合之后为后台开发节省了大量时间. 发现虽然不是完美,整体效果还是不 ...

  9. IMS Global Learning Tools Interoperability™ Implementation Guide

    Final Version 1.1 Date Issued:            13 March 2012 Latest version:         http://www.imsglobal ...

随机推荐

  1. Python基础一(基本类型和运算符)

    在说Python的基本类型钱我们先说下Python注释方式有哪几 Python注释 行注释 #行注释 行注释用以#开头,#右边的所有文字当做说明,而不是真正要执行的程序,起辅助说明作用 # 我是注释, ...

  2. csslint在前端项目中的使用

    大家都听说过jslint,eslint,不过你可能没见过csslint,你可能会问csslint有什么用,为什么今天要说csslint,是因为我在开发中遇到一个坑,其实之前不怎么使用csslint的, ...

  3. Python学习1-Python和Pycharm的下载与安装

    本文主要介绍Python的下载安装和Python编辑器Pycharm的下载与安装. 一.Python的下载与安装 1.下载 到Python官网上下载Python的安装文件,进入网站后显示如下图: 网速 ...

  4. JS中精选this关键字的指向规律你记住了吗

      1.首先要明确:           谁最终调用函数,this指向谁           this指向的永远只可能是对象!!!!!          this指向谁永远不取决于this写在哪,而取 ...

  5. ubuntu 休眠后窗口边缘出现花边的解决方案

    可以确定是nvidia显卡的问题,详细的解决方案请参见:这里 临时的解决方案: compize --replace 永久性的解决方案: sudo add-apt-repository ppa:grap ...

  6. 备份恢复-----system表空间损坏

    无法进行关库,报错如下 SQL> shutdown immediate ORA-01122: database file 1 failed verification checkORA-01110 ...

  7. hive将数据导致本地磁盘

    hive -e "select * from wyp" >> local/wyp.txt   其中我更喜欢弄好临时表,然后交互式查询时让相关人员自己去按逻辑处理数据,最 ...

  8. Mysql安装(绿色版安装)

    一:下载 1.官网 https://dev.mysql.com/ 2.下载 3.下载 二:安装 1.将官网上下载的包进行解压 2.以管理员的身份运行DOS安装 进入mysql的bin目录 运行mysq ...

  9. html5+css3 手机屏幕的适配css

    *{ margin:0;padding:0;outline:0}a{ text-decoration:none}body,html{ font-size:20px;font-family:'Micro ...

  10. LAMP环境使用Composer安装Laravel

    安装Composer 因为使用的Ubuntu服务器,所以我们使用apt安装: 1 $ sudo apt install composer 安装Laravel 首先创建一个项目目录,进入新目录使用Com ...