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 ','.
Related
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")
}
The android application that I'm testing using Appium with Java has the tag/mention users feature. Now I want to test this feature. I'd like to send multiple mentions and verify that the mentions are sent or not. The application that I'm testing is similar to slack/messaging application.
Test case steps:
Open chatroom
Tap on send message field to activate the keyboard
Type # and wait for list of users to tag/mention appear
Tap user 1
Send a space after the user1 is tagged/mentioned
Type # again and wait for list of users to tag/mention appear
Tap user 2
Tap message send button
I'm using page object model. So to perform the above steps I created a method named sendMultiMention in the page class as follows:
#Override
public ChatroomPage sendMultiMention(int index0, int index1){
sendKeyToElement(SENDMESSAGEFIELD, "#");
List<MobileElement> mentionPersonNamesList =
waitAndReturnElementListIfDisplayed(MENTIONPERSONNAME);
MobileElement mentionPersonNameSelect0 = mentionPersonNamesList.get(index0);
tapOnElement(mentionPersonNameSelect0);
sendKeyToElement(SENDMESSAGEFIELD, "#");
MobileElement mentionPersonNameSelect1 = mentionPersonNamesList.get(index1);
tapOnElement(mentionPersonNameSelect1);
tapOnElement(SENDMESSAGEBUTTON);
return this;
}
So the problem with the above code is the 2nd sendKeytoElement overwrites (i.e. clears) the previously filled text in the send message text field.
So what it does is the following:
types # -> selects user1 -> clears #user1 ->types # again -> selects #user2.
But what I want is to do the following:
types # -> selects user1 -> give a space ->types # again -> selects #user2
(i.e. DO NOT CLEAR #user1 FROM THE SEND MESSAGE TEXT FIELD)
Any help will be highly appreciated!
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.
I want to set the signing order in an embedded signing envelope, which means that I have 2 recipients that sign the document one by one. On the sandbox UI that I can tick the checkbox to set the signing order and have 2 recipients there. The second one receives the email after the first one finished. I am wondering how can I implement the same logic by code.
I ve already tried to set the routing order but not what I want.
TemplateRole signer = new TemplateRole();
signer.setEmail(signerEmail);
signer.setName(signerName);
signer.clientUserId(String.valueOf(xxx));
signer.setRoleName("signer");
signer.setRoutingOrder("1");
TemplateRole signer1 = new TemplateRole();
signer1.setEmail("xxx");
signer1.setName("xxx");
signer1.clientUserId(String.valueOf(123));
signer1.setRoleName("signer1");
signer1.setRoutingOrder("2");
envelopeDefinition.setTemplateRoles(Arrays.asList(signer, signer1));
This is what I want:
enter image description here
Not this:
enter image description here
First, if you're referencing a template you'll need to set up the routing order there. When using using TemplateRoles, it's not necessary to set the routing order in the signer definition.
Second, in your code you're hitting signer.setRoutingOrder() twice, looks like you left the 1 off the second reference.
Third, I don't believe "0" is a valid position in the routing order. Try 1 & 2 instead.
I am currently taking a course in app development and I am trying to use Facebooks API for GET requests on certain events. My goal is the get a JSON file containing all comments made on a certain event.
However some events return only a an "id" key with an id number such as this:
{
"id": "116445769058883"
}
That happends with this event:
https://www.facebook.com/events/116445769058883/
However other events such as (https://www.facebook.com/events/1964003870536124/) : returns only the latest comment for some reason.
I am experementing with facebook explore API:
https://developers.facebook.com/tools/explorer/
This is the following GET requests that I have been using in the explorer:
GET -> /v.10/facebook-id/?fields=comments
Any ideas? It's really tricky to understand the response since both events have the privacy set to OPEN.
Starting from v2.4 of the API, the API is now declarative which means you'll need to specify what fields you want the API to return.
For example, if you want first name and second name of the user, then you make a GET request to /me?fields=first_name,last_name else you will only get back the default fields which are id and name.
If you want to see what fields are available for a given endpoint, use metadata field. e.g. GET /me?metadata=true