How to define that inline button is pressed and how to get callbackdata using pengrad/telegram-bot-api library? I have this code to send message with inline keyboard button
private void approveAdmin(User u){
User admin = userService.findByUserRole("ROLE_ADMIN");
SendMessage sm = new SendMessage(admin.getChatId(),
"Do you approve user: "+u.getfName()+" "+u.getlName()+" as admin?");
sm.replyMarkup(new InlineKeyboardMarkup(new InlineKeyboardButton[]
{new InlineKeyboardButton("Approve user.").callbackData(u.getIdUser().toString())}));
BOT.execute(sm);
}
but how to handle update from inline button?
below snippet may helps you:
GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates());
List<Update> updates = updatesResponse.updates();
for (Update update : updates) {
CallbackQuery callbackQuery = update.callbackQuery();
if (callbackQuery != null) {
//use the callbackQuery object peroperties to provide the appropriate response
}
//to make the update handler fully functional, make sure to check other types of messages
}
Related
I'm not really sure how to ask the question, but I'm going to try here.
I've got a list of actions that could happen to a subject. The user of my system needs to approve these actions and does so by selecting (checkboxes) these actions and then clicking the Approve button. Some of these action might require extra data, so a new page is presented to the user. The user enters that new data. Then the backend sends the whole package off to the endpoint for modification on the database. Once completed, it will reload the page they were just on.
So this is how I have it setup:
Approve button jumps to the following method:
#PostMapping("ApproveActions")
public RedirectView approveActions(ModelandView mav, #ModelAttribute("pendingActions") PendingActionsForm pendingActions) {
boolean needsDetails = false;
ActionForm actionForm = new ActionForm();
// parse through each of the actions
pendingActions.forEach(action -> {
// verify if the action has been selected by the user.
if (action.isSelected()) {
// if needsDetails hasn't been set to true,
if (!needsDetails) {
// check to see if it is one of the special actions that needs more info
needsDetails = ActionTypes.NeedsDetails(action.typeId());
}
// build the data for the endpoint
actionForm.addActionData(action);
}
});
if (needsDetails) {
// load the new page
rv.setUrl("/extraActionDetails");
return rv; // This is not right, but it does get me to the new page.
// get data
// return to this point with that new data
actionForm.setExtraDetails(???);
}
actionService.ApproveActions(actionForm);
RedirectView rv = new RedirectView();
rv.setUrl("/subjects/" + pendingActions.getSubjectId() + "#actions-pending");
return rv;
}
The problem I'm having is I don't know how to do that part with // load the new page get data and return to this point with that new data. I've got the extra-details.jsp page built out. And it's controller can be called. Does this question make sense? Are there any tutorials out there that address this situation?
I used the demo app for auto renewing subscriptions to implement autorenewing subscriptions on my app. I am able to log in and subscribe which will bring up the standard ios subscription dialogs. However the next time i Log in i call the iap.isSubscribed() mechanism from Codenameone , the result is always false (Is this because i am in the testflight environment?). When the isSubscribed method returns fault i send the user to the subscribe page which has a button to subscribe, when this button is pressed i get a dialog informing me i am already subscribed.
I have attempted to use the emulator as well as an actual apple iphone6+ neither of which got back the successfully subscribed receipt for the user
#Override
public void initForm() {
theme = UIManager.initFirstTheme("/theme");
//create a new content container
Container content = new Container();
iap = Purchase.getInAppPurchase();
// Pro only feature, uncomment if you have a pro subscription
// Log.bindCrashProtection(true);
// Define a receipt loader
iap.setReceiptStore(createReceiptStore());
/*
The form needs to be split up into 3 parts 1 part for Successful subscriptions
1 part for paymens that have not been sucecssful yet
and 1 part for people who have not subscribed yet
*/
if (!iap.isSubscribed(Skus)) {
EMCDialogFactory.showMessageDialog("Subscription Failed", "Is Subscribed upon login: " + iap.isSubscribed(SKU_1_MONTH));
content = createNonSubscribedHomeScreen();
} else {
EMCDialogFactory.showMessageDialog("Subscription Failed", "Is Subscribed upon login: " + iap.isSubscribed(SKU_1_MONTH));
content = createSuccessfulHomeScreen();
}
setLayout(new BorderLayout());
add(BorderLayout.CENTER, content);
}
/**
* Creates a receipt loader to load receipts from our web service
*
* #return
*/
private ReceiptStore createReceiptStore() {
//fetch all your receipts from the server to be used by the receipt store
listOfReceipts = fetchReceipts();
return new ReceiptStore() {
#Override
public void fetchReceipts(SuccessCallback<Receipt[]> callback) {
List<Receipt> out = new ArrayList<>();
//loop through the receipts
for (Receipt res : listOfReceipts) {
//create a new receipt
Receipt r = new Receipt();
r.setTransactionId(res.getTransactionId());
r.setPurchaseDate(res.getPurchaseDate());
r.setQuantity(1);
r.setSku(res.getSku());
//check cancellation and expiry
if (res.getCancellationDate() != null) {
r.setCancellationDate(res.getCancellationDate());
}
if (res.getExpiryDate() != null) {
r.setExpiryDate(res.getExpiryDate());
}
out.add(r);
}
callback.onSucess(out.toArray(new Receipt[out.size()]));
}
#Override
public void submitReceipt(Receipt r, SuccessCallback<Boolean> callback) {
submitTheReceipt(r, callback);
}
};
}
There is no Error message that shows up it simply returns false that i am not subscribed and it goes back to my subscription page. However if i press my subscribe button again it says that i am already subscribed.
I'm working on a java Applet which has a document loaded. On this Applet I have a custom "print" button which basically inits the print process of the document. This is the code that is executed after this button is pressed:
PropertyValue[] printProperties = new PropertyValue[1];
printProperties[0] = new PropertyValue();
printProperties[0].Name = "Print";
printProperties[0].Value = new Boolean(true);
xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface (XDispatchProvider.class, xFrame);
dispatcher.executeDispatch(xDispatchProvider, ".uno:Print","_self", 0, printProperties);
someOtherProcess();
This code opens the native(?) print dialog which is the expected behaviour, and works so far. The problem is the "someOtherProcess" method. I need to execute this method right after the print dialog is closed either by pressing its "print" button or canceling/closing the print dialog.
Since executeDispatch is async I tried to make it synchronous using the "SynchronMode" in the PropertyValue[] with no success.
I found a way to listen to print events which are fired when the print process starts or when it's cancelled. This is the whole code:
PropertyValue[] printProperties = new PropertyValue[1];
printProperties[0] = new PropertyValue();
printProperties[0].Name = "Print";
printProperties[0].Value = new Boolean(true);
xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface (XDispatchProvider.class, xFrame);
dispatcher.executeDispatch(xDispatchProvider, ".uno:Print","_self", 0, printProperties);
XPrintJobBroadcaster xPrintJobBroadcaster = (XPrintJobBroadcaster)UnoRuntime.queryInterface(XPrintJobBroadcaster.class, xComponent);
xPrintJobBroadcaster.addPrintJobListener(new MyPrintJobListener());
class MyPrintJobListener implements XPrintJobListener {
public void printJobEvent(PrintJobEvent printJobEvent) {
AppletLogger.log("printing");
}
public void disposing(com.sun.star.lang.EventObject eventObject) {
AppletLogger.log("disposing");
}
}
The "printJobEvent" is fired when the print process has either started, finished, cancelled and so on, but I can't find a way to know if the print dialog has been cancelled or closed as this doesn't fire any print event.
So my main questions are, is there a way to open a print dialog in a synchronous way so that the programs waits for the print dialog to close?
Is there a way to listen to the close event of the native print dialog window?
Thanks in advance!
Check the State property. If printing is cancelled, it should first show JOB_STARTED (which is 0) and then JOB_ABORTED (which is 3).
class MyPrintJobListener implements XPrintJobListener {
public void printJobEvent(PrintJobEvent printJobEvent) {
AppletLogger.log("print status: " + printJobEvent.State.getValue());
}
public void disposing(com.sun.star.lang.EventObject eventObject) {
AppletLogger.log("disposing");
}
}
Also the dispatcher didn't work for me. Use the API interface instead:
XPrintJobBroadcaster xPrintJobBroadcaster = (XPrintJobBroadcaster)
UnoRuntime.queryInterface(XPrintJobBroadcaster.class, xComponent);
xPrintJobBroadcaster.addPrintJobListener(new MyPrintJobListener());
XPrintable xPrintable =
(XPrintable)UnoRuntime.queryInterface(XPrintable.class, xComponent);
xPrintable.print(printProperties);
try { Thread.sleep(10000); } catch (Exception e) {} // Wait for print job.
I want to create a workflow which will trigger an email when a new employee_profile component is dragged & dropped into the parsys in profile page. I have created a workflow which is not getting triggered on drag & drop, I have to manually start it from sidekick tab. In launcher I have given path till.
path : /content/demo/en/profile/jcr:content
eventType : modified
contentType : cq:pageContent
I somehow created a workflow to send an email to my gmail account using Java class CustomStep which is containing the code:
#Component
#Service
#Properties({
#Property(name = Constants.SERVICE_DESCRIPTION, value = "Test Email workflow process implementation."),
#Property(name = Constants.SERVICE_VENDOR, value = "Adobe"),
#Property(name = "process.label", value = "Test Email Workflow Process") })
public class CustomStep implements com.day.cq.workflow.exec.WorkflowProcess {
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
//Inject a MessageGatewayService
#Reference
private MessageGatewayService messageGatewayService;
public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {
try
{
log.info("Here in execute method"); //ensure that the execute method is invoked
//Declare a MessageGateway service
MessageGateway<Email> messageGateway;
//Set up the Email message
Email email = new SimpleEmail();
//Set the mail values
String emailToRecipients = "monendra80#gmail.com";
String emailCcRecipients = "monendra.senger#gmail.com";
email.addTo(emailToRecipients);
email.addCc(emailCcRecipients);
email.setSubject("AEM Custom Step");
email.setFrom("monendra80#gmail.com");
email.setMsg("This message is to inform you that a new profile has been added. To find out about the new profile please visit our site.");
//Inject a MessageGateway Service and send the message
messageGateway = messageGatewayService.getGateway(Email.class);
// Check the logs to see that messageGateway is not null
messageGateway.send((Email) email);
}
catch (Exception e)
{
e.printStackTrace() ;
}
}
}
Do I need to give path till /content/demo/en/profile/jcr:content/par1 & change the content type?
Please Suggest something So my workflow can be automated when I drag & drop my component in parsys.
Thanks in advance.
Have you verified your settings in the launcher page indeed? Go to localhost:4502/libs/cq/workflow/content/console.html and select the 4th tab (Launcher). Can you see an entry with your workflow and a particular event type? Please note you can use the workflow page as well to verify whether a workflow ran. Good luck.
I've tried everything and i cant get with the answer, there is not much topics talking about it.
Here the escenario:
Once the user run the app, 2 FrameViews display. The main frame and the login.
Whenever if the user exist, the login frameview must be close and let me edit the main_frame.
But i cannot close the login frameview. Dispose doesnt exist, close neither. What do i have to do?
the login form is name
demo
and the main_frame
main_frame
Suggestions?
Update
HERE the code where the login login must be close
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
String pass = this.jTextField1.getText();
String user = this.jTextField2.getText();
boolean login = db.Qboolean(new String[]{
"SELECT Id_User FROM login WHERE UserName = ? AND Pass = ?",
pass +","+user,
});
if(login)
//what do i have to use here to close it!!!
else
Logs.Mensaje("No se pudo :(");
}
If you're using Netbeans , there is another way (and easy) to check username and password !
you can define a new Jfram in run(){ }
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
//here you can make log in form within while and check if the user is exist
//continue
new Graphic().setVisible(true);
}