Public GreenAPI As BANanoGreenAPI
Sub StartGreenAPI
GreenAPI.Initialize(Me, "greenapi", Main.GreenAPI_Instance, Main.GreenAPI_Token)
GreenAPI.ApiUrl = Main.GreenAPI_APIURL
'this will return the phone number & deviceid
BANano.Await(GreenAPI.GetWaSettings)
'BANano.Await(GreenAPI.GetSettings)
Main.AccountID = GreenAPI.PhoneNumber
Main.AccountAvatar = GreenAPI.Avatar
'
'get the contact information for the account
Dim thisAccount As ContactInfo = BANano.Await(GreenAPI.GetContactInfo($"${Main.AccountID}@c.us"$))
If thisAccount.name = "" Then
app.ShowToastWarning("Please re-login to your GreenAPI instance to establish the name of your account.")
End If
Dim suserName As String = $"${thisAccount.name} - ${thisAccount.chatId} - ${Main.UserName}"$
BANano.Await(UpdateUserName(suserName))
' 'trap incoming messages & files (this can be done once via the instance in web interface)
' Log("Apply settings...")
' GreenAPI.WebhookUrl = Main.GreenAPI_WebHook
' GreenAPI.OutgoingWebhook = "no"
' GreenAPI.OutgoingAPIMessageWebhook = "no"
' GreenAPI.OutgoingMessageWebhook = "no"
' GreenAPI.IncomingWebhook = "yes"
' GreenAPI.OutgoingWebhook = "no"
' GreenAPI.pollMessageWebhook = "no"
' GreenAPI.StateWebhook = "no"
' GreenAPI.StatusInstanceWebhook = "no"
' Dim bSettings As Boolean = BANano.Await(GreenAPI.SetSettings)
' Log(bSettings)
' Log(GreenAPI.deviceid)
' Log(GreenAPI.PhoneNumber)
' Log(GreenAPI.Avatar)
'update the user logo in pgIndex
'UpdateUserName(GreenAPI.PhoneNumber)
'UpdateUserAvatar(GreenAPI.Avatar)
'log out first
'BANano.Await(GreenAPI.LogOut)
'get QR Code
'Dim qr As String = BANano.Await(GreenAPI.GetQRCode)
'Log(qr)
'authorize
'Dim acode As String = BANano.Await(GreenAPI.GetAuthorizationCode)
'Log(acode)
'greenAPI.MediaUrl = "https://7103.media.greenapi.com"
'BANano.Await(GreenAPI.getAccountSettings)
'Dim accountStatus As String = BANano.Await(GreenAPI.GetAccountState)
'Log(accountStatus)
'Dim bResponse As Boolean = BANano.Await(GreenAPI.ReBoot)
'Log(bResponse)
'*****
'send a message to a contact
' Dim sAndile As String = "[email protected]"
' Dim sSiba As String = "[email protected]"
' Dim sMySelf As String = "[email protected]"
' Dim sDean As String = "[email protected]"
' Dim sResp As String = BANano.Await(greenAPI.SendPoll(sMySelf, "Please choose the color", Array("green", "red", "blue"), False, ""))
' Log(sResp)
'Dim idMessage As String = BANano.Await(greenAPI.SendMessage(sSiba, "Da is testing the GreenAPI to send & receive WhatsApp messages for b4x. Please confirm receipt!","",True))
'Log(idMessage)
'
' Dim fileURL As String = "https://drive.google.com/uc?export=download&id=1-G3jNqwkweu4qtN3tntYFjmHtUF5X6FZxxx"
' Dim idMessage As String = BANano.Await(greenAPI.SendFileByUrl(sMySelf, fileURL, "BANanoVuetify 3 - Mock.Compile.Publish.pdf", "BANanoVuetify 3 - Mock.Compile.Publish", ""))
' Log(idMessage)
'Dim mypos As BANanoGeoPosition = BANano.Await(app.GetMyLocation)
'Log(mypos)
'
'Dim idMessage As String = BANano.Await(greenAPI.SendLocation(sAndile, mypos.Latitude, mypos.Longitude, "Home via GreenAPI", "<Address>", ""))
'Log(idMessage)
'
'Dim idMessage As String = BANano.Await(greenAPI.SendContact(sAndile, "Anele", "Mashy", "Mbanga", "27xxx", "Sithaso Holdings BANanoGreenAPI", ""))
'Log(idMessage)
'Dim whatsAppExists As Boolean = BANano.Await(greenAPI.CheckWhatsApp("27xxx"))
'Log(whatsAppExists)
'
'Dim myAvatar As String = BANano.Await(greenAPI.GetAvatarFor(sAndile))
'Log(myAvatar)
'Dim contacts As List = BANano.Await(greenAPI.GetContacts(False))
'Log(contacts)
'
'Dim contact As ContactInfo = BANano.Await(greenAPI.GetContactInfo(sDean))
'Log(contact)
'
'Dim contacts As List
'contacts.Initialize
'contacts.Add(sDean)
'contacts.Add(sSiba)
'contacts.Add(sMySelf)
'Dim grp As Map = BANano.Await(greenAPI.CreateGroup("Group created by BANanoGreenAPI", contacts))
'Log(grp)
'[email protected]
'Dim nGroupID As String = "[email protected]"
'Dim bRenameGroup As Boolean = BANano.Await(greenAPI.UpdateGroupName(nGroupID, "Sithaso BANanoGreenAPI"))
'Log(bRenameGroup)
'
'Dim gd As GroupData = BANano.Await(greenAPI.GetGroupData(nGroupID))
'Log(gd)
'Dim bAdded As Boolean = BANano.Await(greenAPI.AddGroupParticipant(nGroupID, sAndile))
'Log(bAdded)
'
'Dim bRemoved As Boolean = BANano.Await(greenAPI.RemoveGroupParticipant(nGroupID, sAndile))
'Log(bRemoved)
'
'Dim bGroupAdmin As Boolean = BANano.Await(greenAPI.SetGroupAdmin(nGroupID, sDean))
'Log(bGroupAdmin)
'
'Dim bGroupAdmin As Boolean = BANano.Await(greenAPI.SetGroupAdmin(nGroupID, sSiba))
'Log(bGroupAdmin)
'
'Dim bRemoveGroupAdmin As Boolean = BANano.Await(greenAPI.RemoveGroupAdmin(nGroupID, sDean))
'Log(bRemoveGroupAdmin)
'Dim bRemoveGroupAdmin As Boolean = BANano.Await(greenAPI.RemoveGroupAdmin(nGroupID, sSiba))
'Log(bRemoveGroupAdmin)
'*** send file by upload
' Dim assetFile As BANanoObject = BANano.Await(SDUIShared.FetchAsFile("./assets", "mashy.jpg"))
' Dim fileURL As String = BANano.Await(greenAPI.UploadFile(assetFile))
' Log(fileURL)
'
' Dim response As Map = BANano.Await(greenAPI.SendFileByUpload(sMySelf, "Mashy", assetFile, "mashy.jpg", ""))
' If response.ContainsKey("urlFile") Then
' Dim surlFile As String = response.Get("urlFile")
' Dim idMessage As String = BANano.Await(greenAPI.SendFileByUrl(sMySelf, surlFile, "mashy.jpg", "Mashy", ""))
' Log(idMessage)
' End If
'get a file from the assets folder
' Dim bRemoveGroupAdmin As Boolean = BANano.Await(greenAPI.SetGroupPicture(nGroupID, assetFile))
' Log(bRemoveGroupAdmin)
'
' Dim bLeaveGroup As Boolean = BANano.Await(greenAPI.LeaveGroup(nGroupID))
' Log(bLeaveGroup)
'Dim chats As List = BANano.Await(greenAPI.GetChatHistory(sMySelf))
'Log(chats)
'
'Dim chat As Message = BANano.Await(greenAPI.GetMessage("[email protected]", "BAxxx"))
'Log(chat)
'Dim forwards As List = BANano.Await(greenAPI.ForwardMessages(sSiba, sMySelf, Array("BAxxx", "BAxxx")))
'Log(forwards)
'Dim lLastIncomingMessages As List = BANano.Await(greenAPI.LastIncomingMessages(1440))
'Log(lLastIncomingMessages)
'
'Dim lLastOutgoingMessages As List = BANano.Await(greenAPI.LastOutgoingMessages(1440))
'Log(lLastOutgoingMessages)
'***** works for notifications
' Try
' app.PagePause
' Dim message As MessageNotification
' message.Initialize
' Dim messageExists As Boolean = BANano.IsNull(message)
' Do While messageExists = False
' 'trap receive notifications
' message = BANano.Await(greenAPI.ReceiveNotification(20))
' Log(message)
' BANano.Await(greenAPI.DeleteNotification(message.receiptId))
' messageExists = BANano.IsNull(message)
' Loop
' app.pageresume
' Catch
' Log(LastException)
' app.pageresume
' End Try
End Sub