Create telegram bot Keyboard from JSON file depending on user menu selection - telegram-bot

I am creating a telegram bot that requires a dynamic menu to be created depending on the user's previous menu selection. The dynamic menu should pull from a json file and a specific key:value. Required keyboard is the KeyboardButton and NOT an InlineKeyboardButton.
Example: User is presented with a menu that is A-F, G-L, M-R, and S-Z. When they select the button A-F I am looking for a dynamic menu to be built from the json file where Name is sorted from A-F. The user would then select a name from the new menu and information would be presented associated with that name.
I am lost on the dynamic menu portion for the af_menu_keyboard. Other menus are no problem and can retrieve what I need from that json file.
Anyone know how to achieve this?
result = os.popen("curl https://api.mainnet.klever.finance.....")
details = json.load(result)
def messageHandler(update: Update, context: CallbackContext):
if "A-F" in update.message.text:
update.message.reply_text(node_menu_message()),
reply_markup=af_menu_keyboard():
if "Back" in update.message.text:
update.message.reply_text(main_menu_message(),
reply_markup=main_menu_keyboard())
def first_menu_keyboard():
buttons = [[KeyboardButton("A-F"), KeyboardButton("G-L"), KeyboardButton("M-R")],
[KeyboardButton("S-Z"),KeyboardButton("Back", calback_data='main')]]
return ReplyKeyboardMarkup(buttons,resize_keyboard=True)
def af_menu_keyboard():
buttons = **** Create menu with multiple values from the API JSON file above ****
return ReplyKeyboardMarkup(buttons,resize_keyboard=True)

Related

Karate UI automation, is it possible to make locators dynamic

Thanks Peter for API,Perf karate framework.
Now I am trying UI automation and it looks perfect as of now.
I have below question:
I have a menu bar with 15 items in it. they are named as following:
-Home
-Account
-groups
-settings
etc etc.
Locator for each one is like this "a[name=Home]" , "a[name=Account]", "a[name=groups]" . So ony the part after name= is something that is dynamic in nature. So my question is that is it possible to somehow make this dynamic locator?
I have written a called feature in which i have written steps to login and select a menu item. and I want to pass the menu item from calling feature in json like below:
if I want to click on Account menu
* call read(menuItem.feature) {menuItem: Account}
menuItem.feature looks something like below:
Given url 'xyz'
And input (username, userID)
And input (password, password)
And click("button[name=login]")
And click("a[name=Home]")
Here I want to make Home as dynamic in last click step on menuItem.feature so that I can pass other menu items and reuse all above steps/feature file to login everytime with different menu items passed from calling feature file in json{.
Again its just a query. I have currently written multiple scenarios to click on menu item and then in calling feature I call the called feature with tags like #Home,#account etc. and this works perfectly fine.
Also if there is any other better way to achieve this then please suggest
Yes. Let me put it this way, the things you see such as input('foo', 'bar') is pure JS behind the scenes. So normal programming-language rules apply. For example:
* def dynamic = 'foo'
* def locator = 'a[name=' + dynamic + ']'
* input(locator, 'some value')

Need to capture ID after clicking on submit button

I am using selenium with java and In my application , whenever I click on submit button, system generates random ID, I need to capture that ID displayed on screen(a div) and then put in other field to ensure, all fields are filled and we are able to edit as well.
The simpelst way is this:
Create a variable that will contain the id:
String myID;
After id is created you need to capture the text in the filed:
myID = driver.findElement(By.id(".....")).getText();
After this, the ID will be saved in myID.
to see if it worked, run the following line:
System.out.println(myID);
If the output in the console is the same as in a generated ID field then all worked correctly.

Call Pop-Up for WebDynpro from a Business AddIn?

We got a Web Dynpro Application which was created with the Floorplan Manager.
By clicking a specific button I start a Business AddIn which check some conditions and then it should show a popup on the screen with a message for the user.
Is there a way I can accomplish that?
One way to get a PopUp (eg confirmation) window in Floorplan applications is to overwrite the NEEDS_CONFIRMATION method of the Interface IF_FPM_GUIBB_*_EXT inside your feeder-class.
Create a reference to cl_fpm_confirmation_request and put this one in the export-parameter EO_CONFIRMATION_REQUEST of the Method.
By Example:
METHOD if_fpm_guibb_list_ext~needs_confirmation.
DATA li_req TYPE REF TO cl_fpm_confirmation_request.
CASE io_event->mv_event_id.
WHEN 'YOUR_EVENT_ID'.
CREATE OBJECT li_req
EXPORTING
it_confirmation_text = 'Plaintext in Content of Popup'
iv_window_title = 'Title of the Popup'
iv_button_text_approve = 'Text Approve-Button'
iv_button_text_reject = 'Text Reject-Button'
.
eo_confirmation_request = li_confrequ.
ENDCASE.
ENDMETHOD.
The method will be called before the PROCESS_EVENT-Method an will override it when you cancel the popup.
Please be aware that every GUIBB-Implementation has it´s own extension interface, e.g. List, Tree, ...
For a deeper look inside popups in FPM or custom-popups have a look into https://blogs.sap.com/2013/11/26/popups-in-floorplan-manager/

Can't get data from the task object of salesforce to display in visualforce page

I am trying to render as a pdf the comments that are associated with a task. I have created a custom button but when I try to get the data to display there is nothing but the field name and I need the text that is stored.
Here is my code:
<apex:page standardController="Task" renderAs="PDF">
<apex:pageBlock id="thePageBlock">
<apex:pageblocktable value="{!task}" var="AC" id="acTable">
<apex:column value="{!AC.description}"/>
</apex:Pageblocktable>
</apex:pageBlock>
</apex:page>
I did not create a controller class and have no idea how to do this. Basically I store a sent email in the comments and want to print it so if that field can show as a pdf I would be set.
modify permissions for field & object on profile & object level.

Need a Hyperlink control to do several things at once

On my site I have a DataList full of image thumbnails. The thumbnails are HyperLink controls that, when clicked, offer an enlarged view of the source image (stored in my database).
My client wants a facebook Like button on each image and I was hoping to put that in the lightbox window that appears when you click on a thumbnail.
My challenge here is that to generate the info for the Like, I need to create meta tags and each image should, preferably, create it's own meta tags on the fly.
What I can't figure out is how to make the HyperLink click open the lightbox AND create the meta tags at the same time.
Any help will be greatly appreciated.
For a live view of the site, go to http://www.dossier.co.za
The way that we approach similar problems is to hook the onclick event of the href in javascript.
Depending on exactly what you need to do, you can even prevent the standard browser behavior for the hyperlink from executing by returning false from the javascript method.
And in some cases, we just use the hyperlink for "show" by setting the href to "#".
Here is an example that combines all of these concepts:
File Name
In this case, the specified javascript is executed, there is no real hyperlink, and the browser doesn't try to navigate to the specified URL because we return false in the javascript.
Add a Classname to the opening table tag like class="tbl_images" so we can use JQuery to access it. Capture the click on the td and pickup the id of the item. Pass that id to your code as required to generate your meta tags. In the following when the user clicks on an anchor in a td, a function will run.
I use this all the time to access attributes in the td so i can run a function. You could use something like this to pickup values from your image/anchor and create something...
$("#tbl_images > tbody > tr ").each(function () {
//get the id of the tr (if required)
var id = $(this).attr("id");
var ImageTitle = $(this).find("img.Image_Class_Name").attr("title");
//on click of anchor with classname of lighthouse run function,
//passing in our id or other data in the row to our function
$(this).find("td: > a.lighthouse").click(function () {
//update script for this record
MyFunction(id,ImageTitle);
});
});