How to give a blank space after writing some text in session.send();
For example,
session.send('Low : 1<br/><br/>Medium : 2<br/><br/>High : 3<br/><br/>Urgent : 4');
Should give output as
Low : 1
Medium : 2
High : 3
Urgent : 4
Link 1 I've gone through this, but it's relevant for what I am searching for
Here's the code and the screenshot
(session, args) => {
session.dialogData.Email = args.response;
builder.Prompts.text(session, "Set Priority");
const msgText = `Low : 1\n\nMedium : 2\n\nHigh : 3\n\nUrgent : 4`;
const msg = new builder.Message(session).text(msgText).textFormat('markdown');
session.send(msg);
},
Depending on the channel you can use Markdown syntax. Here is an example.
const msgText = `Low : 1
Medium : 2
High : 3
Urgent : 4`;
const msg = new BotBuilder.Message(session)
.text(msgText)
.textFormat("markdown");
session.send(msg);
For Markdown support check the channel inspector here. Actually with markdown you can do more.
I have updated the code to use pre tags. Does that help?
Updated once again. Following is the output:
===================
Although I think the functionality you are trying to achieve can be better achieved by utilizing BotBuilder Prompts library. Here is a sample:
bot.dialog("/", [
function(session) {
BotBuilder.Prompts.choice(
session,
"Select your option: ",
["Low", "Medium", "High", "Urgent"],
{ listStyle: BotBuilder.ListStyle.button }
);
},
function(session, result: any) {
session.send(
`You selected ${result.response.index}: ${result.response.entity}`
);
session.endDialog();
}
]);
Utilizing BotBuilder.Prompts library will also help in validation as the validation for selected option is built into the library, and if user has entered something giberish, the library auto-prompts by itself. Output:
Related
I've looked everywhere and tried all I could think of but found nothing, everything seemed to fail.
One bit of code I've used before that failed:
Message.author.send({ embeds: [AttachmentEmbed] }).then(Msg => {
var Collector = Msg.channel.createMessageCollector({ MessageFilter, max: 1, time: 300000 });
Collector.on(`collect`, Collected => {
if (Collected.content.toLowerCase() !== `cancel`) {
console.log([Collected.attachments.values()].length);
if ([Collected.attachments.values()].length > 0) {
var Attachment = [Collected.attachments.values()];
var AttachmentType = `Image`;
PostApproval(false, Mode, Title, Description, Pricing, Contact, Attachment[0], AttachmentType);
} else if (Collected.content.startsWith(`https://` || `http://`) && !Collected.content.startsWith(`https://cdn.discordapp.com/attachments/`)) {
var Attachment = Collected.content.split(/[ ]+/)[0];
var AttachmentType = `Link`;
PostApproval(false, Mode, Title, Description, Pricing, Contact, Attachment, AttachmentType);
console.log(Attachment)
} else if (Collected.content.startsWith(`https://cdn.discordapp.com/attachments/`)) {
var Attachment = Collected.content.split(/[ ]+/)[0];
var AttachmentType = `ImageLink`;
PostApproval(false, Mode, Title, Description, Pricing, Contact, Attachment, AttachmentType);
console.log(Attachment)
}
[Collected.attachments.values()].length will always be 1. Why? Well you have these 2 possibilities:
[ [] ] //length 1
[ [someMessageAttachment] ] //length 1
The proper way to check is using the spread operator (...)
[...(Collected.attachments.values())].length //returns amount of attachments in the message
I'm adding keyboard to my bot by using InlineKeyboardMarkup. In code below: all buttons are shown in 1 line. How can I achieve that 1 button will be shown per a 1 line?
Thanks for your time.
var mainKeyBoard = new InlineKeyboardMarkup(new[]
{
InlineKeyboardButton.WithCallbackData("beer"), InlineKeyboardButton.WithCallbackData("price"),
InlineKeyboardButton.WithCallbackData("support")
});
Figured it out. New row requires new array into array. For my sample above it work like this:
static InlineKeyboardMarkup mainKeyBoard = new InlineKeyboardMarkup(new[] {
new[]
{
InlineKeyboardButton.WithCallbackData("beer")
},
new[]
{
InlineKeyboardButton.WithCallbackData("price"),
},
new[]
{
InlineKeyboardButton.WithCallbackData("support")
}
});
I have a text file with below example data.
Application.. 4157 10/10/2018 14:24:567 message description 1
Application.. 4157 10/10/2018 14:24:678 message description 2
I want this to be transformed to a below JSON file
{ [ {
"appname" : "Application..",
"PID" : "4157",
"date" : "10/10/2018",
"time" : "14:24:567",
"message":"message description 1" },
{
"appname" : "Application..",
"PID" : "4157",
"date" : "10/10/2018",
"time" : "14:24:,678",
"message":"message description 2" } ] }
Please give me an example how this can be achieved with help of any JSON schema...
I am trying this in node js by reading the text file.
Appreciate your help.
Thanks and Regards,
-Anil Katta
Since you said you can read and process each line, try this code. This code takes the string, removes empty spaces and puts any other words in an array, then you can create the object and pass these array values into object value places, then push the object in your messages array where you will store many messages as objects. When you implement this code with your file, be aware of the loop you are going to use.
Fix credits to Patrick Roberts.
let line = `Application.. 4157 10/10/2018 14:24:567 message description 1`;
const [appname, PID, date, time, ...message] = line.split(' ');
let messages = [];
messages.push({ appname, PID, date, time, message: message.join(' ') });
Example JSON content:
[
{
"appname":"Application..",
"PID":"4157",
"date":"10/10/2018",
"time":"14:24:567",
"message":"message description 1"
},
{
"appname":"Application..",
"PID":"4157",
"date":"10/10/2018",
"time":"14:24:567",
"message":"message description 2"
}
]
Trying to make a very simple Chrome extension. If someone right clicks on a subreddit link, there is a context option to send it to redditp.com instead.
background.js
{
function redpts(info,tab) {
var url = info.linkUrl;
console.log("Link " + info.selectionText + " was clicked to be redditp'd.");
var urlp = url.replace(/reddit.com/i, "redditp.com");
chrome.tabs.create({ url: urlp });
}
chrome.contextMenus.create({
"title" : "RedditP That Shizz!",
"type" : "normal",
"contexts" : ["link"],
"targetUrlPatterns": ["*://*reddit.com/r*"],
"onclick" : redpts
});
}
The error chrome throws is that I have not pattern matched the subreddit URL properly, but I very much tried to follow the formatting instructions of the 'Match Patterns' google page.
Full Error: Unchecked runtime.lastError while running contextMenus.create: Invalid url pattern '*://*reddit.com/r*'
I am a bit cross-eyed trying to see my mistake. Thanks.
Edit: If I comment out the targetUrlPatterns, it works as expected.
Your url pattern should be
"*://*.reddit.com/r*
and you context menu for new chrome version look like be
chrome.contextMenus.create({
"id" : "someuniquerid",
"title" : "RedditP That Shizz!",
"type" : "normal",
"contexts" : ["link"],
"targetUrlPatterns": ["*://*.reddit.com/r*"]
});
chrome.contextMenus.onClicked.addListener(function(e){
if(e.menuItemId == 'someuniquerid') {
chrome.tabs.getSelected(function(tab){
// do you work here
});
}
});
I am developing an API service for my website. The website is about Recipes, where a user is supposed to register on his first visit, then log in. When he logs in he gets an access token, which he uses to do REST services on categories and recipes.
So coming to Recipes, he can give a title, ingredients, and directions. Example:
{
"title" : "api recipe",
"directions" : "Testing api recipe directions",
"ingredient1" : "postman",
"ingredient2" : "ing2",
"ingredient3" : "me",
"ingredient4" : "ingredient4",
"ingredient5" : "ingredient5"
}
Now, I am facing a problem when it comes to PUT method. I want to enable a user to edit a recipe giving only that which he wants to edit. Example:
{
"title" : "PUT"
}
Using PUT method, if a user provides an ingredient as such:
{
"ingredient2" : "Potatoes",
"ingredient5" : "stackexchange"
}
I would like to only change the ingredients that he provided me with and leave the rest the way it is.
Before coming to my question, when a user provides the above, I get a dictionary with the keys and values he/she has provided. My question is, how can I get all the ingredients he wants to edit plus their number?
my code:
data = request.get_json()
category = Category.query.filter_by(user_id=user_id).filter_by(id=category_id).first()
if not category:
return jsonify({'message' : 'category does not exists'})
category.edit_recipe(data, id=recipe_id)
return jsonify({'message' : 'Edited successfully'})
def edit_recipe(self, data, *args, **kwargs):
edit_this = None
if 'id' in kwargs:
edit_this = Recipe.query.filter_by(id=kwargs['id']).filter_by(category_id=self.id).first()
else:
edit_this = Recipe.query.filter_by(title=kwargs['prev_title']).filter_by(category_id=self.id).first()
"""TODO: Get ingredient from data followed by its number.
if data == {'title' = 'change title', 'ingredient2' = 'change ing 2', 'ingredient5' = 'change ing 5'}
then I want to get keys that start with ingredient followed by their number and its value
"""
if 'title' in data:
edit_this.title = data['title']
if 'directions' in data:
edit_this.directions = data['directions']
if 'filename' in data:
edit_this.filename = data['filename']
db.session.commit()
To get only the ingredients, the following below should
keyValue = {
"title" : "api recipe",
"directions" : "Testing api recipe directions",
"ingredient1" : "postman",
"ingredient2" : "ing2",
"ingredient3" : "me",
"ingredient4" : "ingredient4",
"ingredient5" : "ingredient5"
}
oldListOfKeys = keyValue.keys()
ingredientsList = filter(lambda x: x not in ["directions", "title"], oldListOfKeys)
newDict = {key: keyValue[key] for key in keyValue if key in ingredientsList}
print newDict # {'ingredient4': 'ingredient4', 'ingredient5': 'ingredient5', 'ingredient1': 'postman', 'ingredient2': 'ing2', 'ingredient3': 'me'}
(Am using this in a flask app with sqlAlchemy- hope it helps)
In your put method, first query of a specific recipe for example
recipe = Recipe.query.filter_by(recipe_id=id).first()
Then you can access the specific keys like this
data = request.get_json()
recipe.title = data['title']
recipe.directions = data['directions']
recipe.ingredient1 = data['ingredient1']
recipe.ingredient2 = data['ingredient2']