<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Wilik on Medium]]></title>
        <description><![CDATA[Stories by Wilik on Medium]]></description>
        <link>https://medium.com/@wilik?source=rss-45cfa4b5ae47------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VCwt14ypeKuJ5DuQ.</url>
            <title>Stories by Wilik on Medium</title>
            <link>https://medium.com/@wilik?source=rss-45cfa4b5ae47------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 21:48:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wilik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automate QRIS Payment Updates]]></title>
            <link>https://medium.com/@wilik/automate-qris-payment-updates-26fed71d78fe?source=rss-45cfa4b5ae47------2</link>
            <guid isPermaLink="false">https://medium.com/p/26fed71d78fe</guid>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[qris]]></category>
            <category><![CDATA[notification-service]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Wilik]]></dc:creator>
            <pubDate>Sat, 20 Jul 2024 17:06:31 GMT</pubDate>
            <atom:updated>2024-07-20T17:06:31.753Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><p>First of all, QRIS is basically a standardized system for making cashless payments using QR codes in Indonesia. When a person successfully making a payment using our QR code, we will receive an app notification that tell us the amount and the source of payment that they use. See below screenshot for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nlr8Nt6mFQPCUvMLdKgPag.jpeg" /><figcaption>Successful QRIS Payment Notification from DANA app</figcaption></figure><p>Since the notification is sent to only one phone, if you manage a business and the app is on your personal phone, the payment notification will not be received by other employees. This means they won’t know if a customer’s payment is received successfully unless you are around.</p><h3>Ideas</h3><p>Here are some solution ideas to address this issue:</p><ol><li>Buy a dedicated phone</li><li>Install the app on your employee’s phone (this might not work if the app doesn’t allow multi-device login, poses a risk since the employee will have access to the money)</li><li>Create an app!</li></ol><p>In this article, we’ll explore the third option. The main idea is to develop an app that listens for notifications from the payment app, parses the data, and then sends it to a shared channel like a Telegram group or Discord channel.</p><h3>Solution</h3><p>Since the solution requires us to listen for app notification, the platform is limited to Android only by utilizing <a href="https://developer.android.com/reference/android/service/notification/NotificationListenerService">NotificationListenerService</a>. As far as I know, iOS doesn’t have this capability yet due to privacy reason.</p><p>Also, we will use Telegram for the shared channel, feel free to modify according to your needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*JklQxezhA7VyPTBKZ1KtQQ.png" /><figcaption>App Diagram</figcaption></figure><h3>Prerequisite</h3><ul><li>Android Studio <a href="https://developer.android.com/studio">https://developer.android.com/studio</a></li><li>QRIS merchant app, or actually anything that you want to read the notification and send to other channel</li><li>a Telegram Bot token that has joined a group (I will create a separate guide for this depending on requests or temporarily <a href="https://www.google.com/search?q=bot+token+telegram+chat+id">https://www.google.com/search?q=bot+token+telegram+chat+id</a>)</li></ul><h3>Create New Android Project and Setup Permissions</h3><p>Follow this official <a href="https://developer.android.com/studio/projects/create-project">Create a project</a> guide to create a new Android project, just choose <strong>Empty Activity</strong> since our app is a background/service app and we need the activity to ask for permissions later.</p><p>Open AndroidManifest.xml file and add below permissions</p><pre>&lt;manifest&gt;<br>  &lt;uses-permission android:name=&quot;android.permission.BIND_NOTIFICATION_LISTENER_SERVICE&quot; /&gt;<br>  &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;<br><br>  ...<br>  &lt;application&gt;<br>  &lt;/application&gt;<br>&lt;/manifest&gt;</pre><p>We need BIND_NOTIFICATION_LISTENER_SERVICE to be able to listen for notifications from our phone, and INTERNET to call the Telegram API to send the message to a Telegram group.</p><h3>Setup NotificationListenerService Class</h3><p>This class will be the service that will handle notifications that we received from the Android system. So we will filter out other app’s notification in this class including parsing the data.</p><p>Create a new Kotlin class for this, in this example NotificationListener.kt</p><pre>class NotificationListener : NotificationListenerService() {<br>    override fun onNotificationPosted(sbn: StatusBarNotification) {<br>        val packageName = sbn.packageName<br>        val notificationText = sbn.notification.extras.getString(&quot;android.text&quot;)<br><br>        Log.d(&quot;NotificationListener&quot;, &quot;Notification from: $packageName&quot;)<br>        Log.d(&quot;NotificationListener&quot;, &quot;Notification text: $notificationText&quot;)<br><br>        // Skip process if the notification is not from &quot;id.dana&quot; app or the text is null<br>        if (!packageName.equals(&quot;id.dana&quot;) || notificationText == null) {<br>            return<br>        }<br><br>        // Regex matching to parse the notification text<br>        val danaQris: Pattern = Pattern.compile(&quot;^Kamu berhasil menerima (.*) via (.*) ke akunmu. Cek yuk!\$&quot;)<br>        val danaQrisMatcher: Matcher = danaQris.matcher(notificationText)<br><br>        if (danaQrisMatcher.matches()) {<br>            val paymentMethod = danaQrisMatcher.group(2)<br>            val amount = danaQrisMatcher.group(1)<br><br>            Log.d(&quot;NotificationListener&quot;, &quot;Payment method : $paymentMethod&quot;)<br>            Log.d(&quot;NotificationListener&quot;, &quot;Amount : $amount&quot;)<br><br>            // Call Telegram API or do other thing with this data.<br>        }<br>    }<br><br>    override fun onNotificationRemoved(sbn: StatusBarNotification) {<br>        // Do nothing here<br>    }<br>}</pre><p>For every notification that we received from the Android system, onNotificationPosted will be triggered, that means we have to filter the package name manually so that we only process notification that we want. In this case, we use <a href="https://developer.android.com/reference/android/service/notification/StatusBarNotification#getPackageName()">StatusBarNotification.getPackageName</a> to get the package name and then checks if it matches with the QRIS Merchant App (id.dana for my example).</p><p>I also have added the parsing capability via regex to parse the notification text so that we can customize our message later to Telegram. Or, you can simply forward the whole notificationText if you want to.</p><p>Next, we will register our newly created NotificationListener class to the manifest to register it as a service.</p><pre>&lt;manifest&gt;<br>  ...<br>  &lt;application&gt;<br>    &lt;activity&gt;<br>      ...<br>    &lt;/activity&gt;<br>    <br>    &lt;service<br>      android:name=&quot;.NotificationListener&quot;<br>      android:exported=&quot;true&quot;<br>      android:label=&quot;@string/app_name&quot;<br>      android:permission=&quot;android.permission.BIND_NOTIFICATION_LISTENER_SERVICE&quot;&gt;<br>      &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.service.notification.NotificationListenerService&quot; /&gt;<br>      &lt;/intent-filter&gt;<br>    &lt;/service&gt;<br>  &lt;/application&gt;<br>&lt;/manifest&gt;</pre><p>Finally, we will have to launch notification access settings page when we first open the page so that the user can allow notification read access to our app. Edit MainActivity.kt file</p><pre>override fun onCreate(savedInstanceState: Bundle?) {<br>  super.onCreate(savedInstanceState)<br>  startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS))<br>}</pre><p>Try to launch this app into your Android device or emulator, it will open App Notification Settings page, you have to allow your app to read notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*_TztKSS3Wkqh6k4LkEgJQQ.gif" /></figure><h3>Call Telegram API</h3><p>We will use a networking library called okhttp to handle the API call, so let’s add the library into our dependency. Open app/build.gradle.kts</p><pre>dependencies {<br>  implementation(&quot;com.squareup.okhttp3:okhttp:4.12.0&quot;)<br>}</pre><p>then <strong>Sync Now</strong>.</p><p>Then create a class to handle the Telegram API call, let’s call it TelegramSender.kt</p><pre>object TelegramSender {<br>  private val client = OkHttpClient()<br>  private const val BOT_TOKEN = &quot;&quot;<br>  private const val CHAT_ID = &quot;&quot;<br>  private const val TELEGRAM_API_URL = &quot;https://api.telegram.org/bot$BOT_TOKEN/sendMessage&quot;<br><br>  suspend fun sendMessage(message: String) {<br>    val json = &quot;&quot;&quot;{&quot;chat_id&quot;:&quot;$CHAT_ID&quot;,&quot;text&quot;:&quot;$message&quot;}&quot;&quot;&quot;<br>    val body = json.toRequestBody(&quot;application/json; charset=utf-8&quot;.toMediaType())<br><br>    val request = Request.Builder()<br>      .url(https://medium.com/TELEGRAM_API_URL)<br>      .post(body)<br>      .build()<br><br>    withContext(Dispatchers.IO) {<br>      client.newCall(request).execute().use { response -&gt;<br>        if (!response.isSuccessful) throw IOException(&quot;Unexpected code $response&quot;)<br>      }<br>    }<br>  }<br>}</pre><p>Make sure to fill BOT_TOKEN and CHAT_ID constant. Basically this will call sendMessage endpoint from Telegram API to send message to a group (with id of CHAT_ID) using a credential of a bot (identified via BOT_TOKEN).</p><p>Then make sure to call this TelegramSender.sendMessage() method inside NotificationListener class that we created previously.</p><h3>Result</h3><p>Now, run the app on your device. When the desired app notification appears, you’ll receive a Telegram message from your bot. You can then invite anyone you want to receive the message to the group.</p><p>Here is the sample result, I returned the whole notification including the parsed data in NotificationListener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*JV6i-csdk8uHXfDLLDQkdA.png" /></figure><p>I hope you find this article useful. Please let me know if there are any areas where I can improve.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26fed71d78fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>