Hello, I would like to introduce you to my new auto-response library for social networks, compatible with whatsapp, telegram works in the background

A good part of the code was recovered from the NotificationListener library I made some modifications to adapt to my project and I'm making available to you the example and the ReplyAuto.rar library.

Sorry for my English, I'm Brazilian and I'm in love with Basic4Android. no more conversations Let's go to the example.

Important minSdkVersion="14" AND android:targetSdkVersion="29"


Manifest:
AddApplicationText(
<service android:name="b4a.jsaplication.com.br.ReplyAuto"
    android:label="ReplyAuto"
          android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
     <intent-filter>
         <action android:name="android.service.notification.NotificationListenerService" />
     </intent-filter>
 </service>)


B4A:
Sub ReplyAuto_NotificationPosted (SBN As StatusBarNotification)
    'Log(SBN.Id) 'get Id Notification
    'Log(SBN.PackageName) 'get PackageName Application posted Notification
    'Log(SBN.Notification) 'get Notification object
    'Log(SBN.Extras)  'get extras Notification
    'Log(SBN.ContentIntent) 'get ContentIntent not used
    'Log(SBN.Key) 'get Key
    'LogColor(SBN.Title, Colors.Green)
    'LogColor(SBN.Message, Colors.Green)
    
    If SBN.PackageName == "com.whatsapp" Then
        Dim whatsappkey As String = SBN.Key
        Dim ww() As String = Regex.Split("\|", whatsappkey)
        If ww(3) <> "null" Then
            'rp.ClearNotification(SBN)
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld WhatsApp")
            Log("Reply Whatsapp Success")
        End If
    End If
    

    If SBN.PackageName == "com.whatsapp.w4b" Then
        Dim whatsappkey As String = SBN.Key
        Dim ww() As String = Regex.Split("\|", whatsappkey)
        If ww(3) <> "null" Then
            'rp.ClearNotification(SBN)
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld WhatsApp-Business")
            Log("Reply Whatsapp Success")
        End If
    End If
    
    If SBN.PackageName == "org.telegram.messenger.web" Then
        Dim telegramkey As String = SBN.Key
        Dim tt() As String = Regex.Split("\|", telegramkey)
        
        If tt(2).Length <> "1" Then
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld Telegram")
            Log("Send Telegram Success")
        End If
    End If
    
    If SBN.PackageName == "org.telegram.messenger" Then
        Dim telegramkey As String = SBN.Key
        Dim tt() As String = Regex.Split("\|", telegramkey)
        
        If tt(2).Length <> "1" Then
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld Telegram")
            Log("Send Telegram Success")
        End If
    End If
    

End Sub
 

Attachments

  • ReplyAuto Library.rar
    16.9 KB · Views: 735
  • ReplyAuto.zip
    9.5 KB · Views: 717

gainax00

Member
Hola!! en Android 6.x me retorna doble respuesta (mensaje) porqué? y no me detecta Telegram

Hello!! in Android 6.x it returns me a double response (message) why? and Telegram does not detect me

Screenshot_20220317-143623.png
 

hanyelmehy

Active Member
Licensed User
Longtime User
i try lib with Instagram (com.instagram.android)
income message detected but when try
B4X:
rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld instgram")
i get message (not success)
any idea ?
 

jsaplication.mobile

Member
Licensed User
B4A:
    'This code checks if a notification has already been responded to. if already answered it does not run until a new one works.
    If SBN.PackageName == "com.whatsapp" Then
        Dim whatsappkey As String = SBN.Key
        Dim ww() As String = Regex.Split("\|", whatsappkey)
        If ww(3) <> "null" Then
            'rp.ClearNotification(SBN)
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld WhatsApp")
            Log("Reply Whatsapp Success")
        End If
    End If
    
    ''This code checks if a notification has already been responded to. if already answered it does not run until a new one works.
    If SBN.PackageName == "com.whatsapp.w4b" Then
        Dim whatsappkey As String = SBN.Key
        Dim ww() As String = Regex.Split("\|", whatsappkey)
        If ww(3) <> "null" Then
            'rp.ClearNotification(SBN)
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld WhatsApp-Business")
            Log("Reply Whatsapp Success")
        End If
    End If
    
    'This code checks if a notification has already been responded to. if already answered it does not run until a new one works.
    If SBN.PackageName == "org.telegram.messenger.web" Then
        Dim telegramkey As String = SBN.Key
        Dim tt() As String = Regex.Split("\|", telegramkey)
        
        If tt(2).Length <> "1" Then
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld Telegram")
            Log("Send Telegram Success")
        End If
    End If
    
'renome to packeger app telegram.
    If SBN.PackageName == "org.telegram.messenger" Then
        Dim telegramkey As String = SBN.Key
        Dim tt() As String = Regex.Split("\|", telegramkey)
        
        If tt(2).Length <> "1" Then
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld Telegram")
            Log("Send Telegram Success")
        End If
    End If
    

End Sub
 

gainax00

Member
B4A:
    'This code checks if a notification has already been responded to. if already answered it does not run until a new one works.
    If SBN.PackageName == "com.whatsapp" Then
        Dim whatsappkey As String = SBN.Key
        Dim ww() As String = Regex.Split("\|", whatsappkey)
        If ww(3) <> "null" Then
            'rp.ClearNotification(SBN)
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld WhatsApp")
            Log("Reply Whatsapp Success")
        End If
    End If
   
    ''This code checks if a notification has already been responded to. if already answered it does not run until a new one works.
    If SBN.PackageName == "com.whatsapp.w4b" Then
        Dim whatsappkey As String = SBN.Key
        Dim ww() As String = Regex.Split("\|", whatsappkey)
        If ww(3) <> "null" Then
            'rp.ClearNotification(SBN)
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld WhatsApp-Business")
            Log("Reply Whatsapp Success")
        End If
    End If
   
    'This code checks if a notification has already been responded to. if already answered it does not run until a new one works.
    If SBN.PackageName == "org.telegram.messenger.web" Then
        Dim telegramkey As String = SBN.Key
        Dim tt() As String = Regex.Split("\|", telegramkey)
       
        If tt(2).Length <> "1" Then
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld Telegram")
            Log("Send Telegram Success")
        End If
    End If
   
'renome to packeger app telegram.
    If SBN.PackageName == "org.telegram.messenger" Then
        Dim telegramkey As String = SBN.Key
        Dim tt() As String = Regex.Split("\|", telegramkey)
       
        If tt(2).Length <> "1" Then
            rp.reply(SBN.Notification, SBN.PackageName, "Reply HelloWorld Telegram")
            Log("Send Telegram Success")
        End If
    End If
   

End Sub
Excelente!!! lo estaba implementando mal ??
Excellent!!! I was implementing it wrong
 

gainax00

Member
Does not capture notifications in android 6.0.1 why will it be?

No captura las notificaciones en android 6.0.1
porqué sera?
 

cheveguerra

Member
Licensed User
Longtime User
Hi, is it possible to know if the sender is a group or a person??

Hola, es posible saber si el que manda el mensaje es un grupo o un chat individual?

Best regards
 

jsaplication.mobile

Member
Licensed User
Oi, é possível saber se o remetente é um grupo ou uma pessoa??

Hola, es possible saber si el que manda el mensaje es un grupo ou un chat individual?

Atenciosamentena ve

Hi, is it possible to know if the sender is a group or a person??

Hola, es posible saber si el que manda el mensaje es un grupo o un chat individual?

Best regards

SBN.title

Essa função verifica o nome do remetente.. quando é um contato que não está salvo nos contatos ele mostra o Numero caso contrário o Nome do remetente ou o nome do grupo
 

cheveguerra

Member
Licensed User
Longtime User
Hi again, it seems that when (In whatsapp) the message comes from a group, in title you get “group name”: “sender name, so if you search for ": " in the title, you can know if the message comes from a group or from an individual chat, so I made this function:

isGroupWA:
Sub isGroupWA(msgSender As String) As Boolean
    Private x As Boolean = Regex.ismatch(".*(: ).*", msgSender)
    Return x
End Sub

if isGroupWA(SBN.title) then
      ... do something only if message comes from a group
End If
So maybe someone finds it useful!!

Best regards
 

cheveguerra

Member
Licensed User
Longtime User
Here some other functions to get info from the notification object (SBN):

B4X:
'Searches the provided sbn.title for the string ": " to know if the sender is a group.
Sub isGroupWA(sbnTitle As String) As Boolean
    Private x As Boolean = Regex.ismatch(".*(: ).*", sbnTitle)
    Return x
End Sub

'Searches the provided notification object for the string "channel=group" and if found returns TRUE.
Sub isGroupWA2(sbn As StatusBarNotification) As Boolean
    Private y As Int = sbn.As(String).IndexOf("channel=group") 'ignore
    Private z As Boolean = False
    If y > -1 Then z = True
    Return z
End Sub

'Searches the provided notification object for the string "@s.whatsapp.net" and if found returns TRUE.
Sub isPersonWA(sbn As StatusBarNotification) As Boolean
    Private y As Int = sbn.As(String).IndexOf("@s.whatsapp.net") 'ignore
    Private z As Boolean = False
    If y > -1 Then z = True
    Return z
End Sub

'Searches the provided notification object for the string "channel=individual" and if found returns TRUE.
Sub isPersonWA2(sbn As StatusBarNotification) As Boolean
    Private y As Int = sbn.As(String).IndexOf("channel=individual") 'ignore
    Private z As Boolean = False
    If y > -1 Then z = True
    Return z
End Sub

'Returns the sender's number.
'Searches the provided notification object and gets the numbers between "shortcut=" and "@s.whatsapp.net".
Sub getNumberWA(sbn As StatusBarNotification) As String
    Private a As Int = sbn.As(String).IndexOf("@s.whatsapp.net") 'ignore
    If a > -1 Then
        Private x As String = sbn.As(String) 'ignore
        Private y As Int = x.IndexOf("shortcut=")
        x = x.SubString2(y+9, a)
    Else 'It is probably is a group.
        x = "Not a person."        
    End If
    Return x
End Sub

'Returns the person's name when the message comes from a group.
'Searches the provided sbn.title for the string ": " in the title and returns the string after that, if does not find ": " then returns the complete string.
Sub getPersonFromGroup(sbnTitle As String) As String
    Private a As Int = sbnTitle.IndexOf(": ")
    If a = -1 Then a = -2 'Is not from a group.
    Private b As String = sbnTitle.SubString(a+2)
    Return b
End Sub
 

jsaplication.mobile

Member
Licensed User
Aqui estão algumas outras funções para obter informações do objeto de notificação (SBN):

[CÓDIGO=b4x]

'Pesquisa o sbn.title para saber se a string ": " o remetente é um grupo.
Sub isGroupWA(sbnTitle As String) As Boolean
Private x As Boolean = Regex.ismatch(".*:) ).*", sbnTitle)
Retornar x
Finalizar Sub

'O objeto de necessidade é requerido pela string "channel=group" e, se encontrado, retorna TRUE.
Sub isGroupWA2(sbn As StatusBarNotification) As Boolean
Private y As Int = sbn.As(String).IndexOf("channel=group") 'ignore
Private z As Boolean = False
Se y > -1 Então z = Verdadeiro
Retornar z
Finalizar Sub

'O objeto 'necessário é requerido pela string "@s.whatsapp.net" e, se encontrado, retorna TRUE.
Sub isPersonWA(sbn As StatusBarNotification) As Boolean
Private y As Int = sbn.As(String).IndexOf("@s.whatsapp.net") 'ignore
Private z As Boolean = False
Se y > -1 Então z = Verdadeiro
Retornar z
Finalizar Sub

'O objeto de necessidade é requerido pela string "canal=individual" e, se encontrado, retorna TRUE.
Sub isPersonWA2(sbn As StatusBarNotification) As Boolean
Private y As Int = sbn.As(String).IndexOf("canal=individual") 'ignore
Private z As Boolean = False
Se y > -1 Então z = Verdadeiro
Retornar z
Finalizar Sub

'Retorna o número do remetente.
'O objeto 'Pesquisa é necessário e obtém os números entre "shortcut=" e "@s.whatsapp.net".
Sub getNumberWA(sbn As StatusBarNotification) As String
Private a As Int = sbn.As(String).IndexOf("@s.whatsapp.net") 'ignore
Se a > -1 Então
Private x As String = sbn.As(String) 'ignore
Private y As Int = x.IndexOf("shortcut=")
x = x.SubString2(y+9, a)
Else 'É provavelmente é um grupo.
x = "Não é uma pessoa."
Fim se
Retornar x
Finalizar Sub

'Retorna o nome da pessoa quando a mensagem vem de um grupo.
'Pesquisa o sbn.title no título e requerido pela string ": " Retorna a string depois disso, se não encontrar ": então retorna a string completa.
Sub getPersonFromGroup(sbnTitle As String) As String
Private a As Int = sbnTitle.IndexOf(": ")
Se a = -1 Então a = -2 'Não é de um grupo.
Privado b As String = sbnTitle.SubString(a+2)
Retornar b
Finalizar Sub
[/CÓDIGO]
Thanks for sharing your knowledge I'm working on version 1.1 with new features and more app support.
 

cheveguerra

Member
Licensed User
Longtime User
Hi, in some cases the previous function didn't return the correct result, so I changed the searched string.

Change function:
'Searches the provided notification object for the string "@g.us" and if found returns TRUE.
Sub isGroupWA2(sbn As StatusBarNotification) As Boolean
    Private a As Boolean = False
    If sbn.As(String).IndexOf("@g.us") > -1 Then a = True 'ignore
    Return a
End Sub
 

tex22

Member
Licensed User
Longtime User
Hi, this is very useful. Specially after Meta's new policies.

Is it possible to receive and save photo/files/audio/location? And also send them?

Oi, isto será muito útil. Especialmente depois das noves políticas da Meta.

É possível receber e salvar fotos/arquivos/audio/localização? E também tem como enviá-los?
 
Last edited:
Top