SmsUserConsentAPI to read sender name with first two letter dynamic - java

I am using UserConsentAPI for reading SMS in Android App, In that there is a method
startSmsUserConsent()
In this method we need to pass sender Number/Name, For example my sender name is ViCARE,
I received VT-ViCARE, BT-ViCARE, AD-ViCare like that each time.First two character of sender name is dynamically changed. If I give below like that reading particular sms from "VT-ViCARE" it works fine, How to read the sender contain "??-ViCARE" using User Consent API?
smsRetrieverClient.startSmsUserConsent("VT-ViCARE")

I did research a lot but currently can't find an exact answer to your question but here is a workaround. How about you call the String's contains method, check if the sender name contains ViCARE, and then pass it to startSmsUserConsent ?
Boolean sender = "YourDynamicSender".contains("ViCARE");
if (sender) {
val task1 = SmsRetriever.getClient(applicationContext).startSmsUserConsent("YourDynamicSender")
}

Related

Send FulfillmentMessage and FollowupEventInput through webhook

In my first Dialogflow project, there are certain points where I've got to send some response and move on to another intent (which also sends text) directly after that.
I tried using a webhook to send that message and make a FollowupEventInput with the code below.
final SessionName sessionName = SessionName.parse(webhookRequest.getSession());
final WebhookResponse.Builder builder = WebhookResponse.newBuilder()
.addFulfillmentMessages(
Intent.Message.newBuilder().setText(Intent.Message.Text.newBuilder()
.addText("This is the text I want to send.")
.build()))
.addOutputContexts(
Context.newBuilder().setName(ContextName.of(sessionName.getProject(), sessionName.getSession(), "Oilchange-haventchecked-followup").toString()
).setLifespanCount(1)
.build())
.setFollowupEventInput(EventInput.newBuilder().setName("StandstillQuestion").setLanguageCode("en"));
return builder.build();
}
The expected result would be:
bot: This is the text I want to send.
bot: This is the text from the next intent
The result I got:
bot: This is the text from the next intent
After that, I researched what the problem was and came upon this stackoverlow question where basically the same was asked (but in Python).
There wasn't a suitable answer to the question.
So I decided to ask it again.
How would I solve this?
I cannot simply add the text from the one intent to the other, because there's multiple intents that have to direct to that second one.
That is the expected behavior as when you set a followup event it basically tells dialogflow to trigger another work flow. But to get around this issue what you would want to do is when you set the followup event, also set a context with the first sentence that you want to say with the second sentence. Then in the fulfillment of your follow up intent, check if that context is set and has any value, if it does then say that too.

How to get previous message's text with a Telegram bot?

I am building a reply keyboard oriented bot using java and I need it to treat differently two scenarios in which the latest message's text is the same based on the text of the previous message. How can I get or store the text of the previous message as a public variable?
My conceptual modelling is as follows:
I have a large If-Else-If statement where the condition for each If block goes along the lines of if(update.hasMessage() && messageText.equals("aaa")) where "aaa" is some text that appears on a reply keyboard that popped up for the user earlier (since the keyboard buttons send the string on them as text and there is no option for a button press event in Telegram bot's api). messageText is defined as update.getMessage().getText().
I want the code to treat differently two scenarios in which messageText is the same based on the message that came before it. if(update.hasMessage() && messageText.equals("aaa") && previousMessage.equals("bbb")) { } else if(update.hasMessage() && messageText.equals("aaa") && previousMessage.equals("ccc")){}. How can I store the previous message without it getting updated upon a new message recieved?
There are lots of patterns that you can use for controlling the state of users, But as a simple trick what I did in my telegram bot, you can generate next message data based on current message response. For example when user send "aaa" as the first message response, and you want to generate the next message you can add first message data to it's callback like this: "aaa,bbb" and when calls the api you notice that previous message was "aaa" by splitting the callback data with ','.

How to get a list of messages on Android device - keep access to extra info

I was just wondering how I would get a list of messages on an Android device where I would have access to the information held by each message (particularly the time it was received, whether it was read, unread, or sent).
I found this answer, but it only seems to get the body of the messages and I would like to have more info than that.
Using new Telephony content provider to read SMS
I thought of making my own sms-like class that would contain the appropriate information I need and then somehow individually pulling that info and storing it, but I would imagine the Android api has some sort of sms class that I am somehow overlooking.
If someone could explain what is happening in the below code it might answer my question. I suspect changing the new String[] { Telephony.Sms.Inbox.Body } parameter might allow me to get the info I need, but I'm just not sure. Any help?
Cursor c = cr.query(Telephony.Sms.Inbox.CONTENT_URI, // Official CONTENT_URI from docs
new String[] { Telephony.Sms.Inbox.BODY }, // Select body text
null,
null,
Telephony.Sms.Inbox.DEFAULT_SORT_ORDER);
There's rather a lot you can select, I suggest you refer to the available Telephony.Sms.Inbox, and android.provider.Telephony.TextBasedSmsColumns -
For example, change
new String[] { Telephony.Sms.Inbox.BODY },
to
new String[] { Telephony.Sms.Inbox.ADDRESS,
Telephony.Sms.Inbox.BODY, Telephony.Sms.Inbox.DATE_SENT },
to also get The address of the other party and The date the message was sent.

How to download refrences part of emails using java?

I am trying to download the email using imap java ..I have downloaded most of the part of email but don't know how to download references part of email?Can someone provide help about which function is used to do that?any links to some page would be helpful.Thanks
References: <CALdDwZ=PQDu2eS1R2ONsrHJDgHDeZuNCUfEsfRqC3efzZfMaqg#mail.gmail.com>
<CAAD0KRhD7w1qdRiTG6U00ShroE1R00h7F73_AQ4yRnDE7jm6HA#mail.gmail.com>
<CALdDwZm2np83PmjrHY1jO54+6-dNKaM7+oxjaUHE_rUitMffrA#mail.gmail.com>
<CAAD0KRg2TJt0Y4oo-CsOCexrmat6kHakuFZSm_AvTDuSXjiTTw#mail.gmail.com>
<CAAD0KRhXUUwNjcAhc+4h-ftiJFW7q0y9gmDRGZ0khzyzWUDxbQ#mail.gmail.com>
<CAAD0KRgp6nhupkQhu2LWe6mXGuvK35XFdZLUUjfC4uGvsOZtcQ#mail.gmail.com>
<CAAD0KRhXaJ5FAuOxR760HBzgaD-_JyXoVAymeQf+nQdCawEgGA#mail.gmail.com>
These are message Id's of all the mails which took part in a conversation..Usually this is a part of an email.so I want to download it?
For downloading the References part of the email we need to use getHeader() function of Imap java ..This is the code :
if( msg.getHeader("References")!=null)
{
String[] headers = msg.getHeader("References");
System.out.println("headers");
for(int ab=0;ab<headers.length;ab++)
System.out.println(headers[ab]);
}
The references are Message-IDs. There's no way to directly access a message given the Message-ID. You can use the Folder.search method to search for messages with the given Message-ID in the specified folder, but there's no way to know what folder the message might have been moved to, nor is there any guarantee that the current user ever saw the referenced message.

simple example of native app passing string to website?

Can somebody give a simple example for java code of a native app passing a string to a website?
For example: when a string has the value Hello everybody, the text Hello everybody should get pasted into the Google search field.
For the most simple use, you can try:
public static void browseURL(Activity activity, String url)
{
try
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);
}
catch (Exception e)
{
message(activity, "Sorry, failed to view the desired page.");
}
}
and then call:
browseURL("http://www.google.com/search?q=Hello+World")
Do you want to fill the fields and submit them? If so, just do the request with the request parameters filled, and parse the response given by the server. Look into Apache HttpClient.
You don't actually have to add text to the Google search field explicitly. You can send a URL with a query string.
Depending on the website the query string will always be different. For Google it is http://www.google.ca/search?q=something . Anything after a ? is considered a query string which any good web developer will include in a webpage. That query string takes custom commands in the form of ?command=query for command&command2=query for command 2.
Since this is tagged blackberry, I assume you want to implement a blackberry app, and you don't explicitly explain what you want to do, so you have two options,
Invoke the browser
On that page it describes how to open a browser session. So within the
browserSession.displayPage("http://http://www.google.ca/search?q=searching%20for%20something");
If you need a class for URL encoding, let me know and I'll send one your way.
Http Request to pull the html of the webpage into the code. To do that, you'll have to look at my blog this week as I'll be posting a full in code network class either tomorrow or tuesday, which I'll edit this post to contain a link to.
OR you can send me a message if you need it NOW and I can email the non-cleaned up code to you.

Categories

Resources