Chat Bot Hero card title message not wrapped properly - node.js

I have created hero card for messages with prompt buttons from qna maker. The hero card embedded response has a title and buttons. The buttons are displayed properly and worked as expected, but the title words are not wrapped properly.
if (resResult) {
var answer = resResult.answer;
var resultContext = resResult.context;
var prompts = resultContext && resultContext.prompts;
if (prompts && prompts.length) {
var card = CardFactory.heroCard(
answer,
[],
prompts.map(prompt => ({
type: 'messageBack',
title: prompt.displayText,
displayText: prompt.displayText,
text: prompt.displayText,
value: {
qnaId: prompt.qnaId
}
}))
);
answer = MessageFactory.attachment(card);
}
await context.sendActivity(answer);
}
The output response in chat window / Emulator is
The title text which is displayed needs to wrapped and font style and color should align with common text styles of chat bot.
Thanks in advance

Related

Electron - Passing program information to windows media volume control overlay

I'm building a music player and I want to give windows information like the current song's title and artist, and the album art in the popup in the attached picture. It currently display's the song name by changing the <title/> of the page.
Using Electron, HTML, and JavaScript, is this possible?
(Please ask if you need to see any code, I'm not sure what'd be helpful and what would just clutter the question so just ask)
assigned vars are:
songName - songs name,
albumName - albums name,
artistName - artists name,
res - album art,
lyrics - songs lyrics
Yes, this is posible.
You can do this using Media Session API.
Media Session API allows a web page to provide custom behaviors for standard media playback interactions, and to report metadata that can be sent by the user agent to the device or operating system for presentation in standardized user interface elements.
Plus, you can take control about play, pause, previous track and next track buttons.
You can read more about it in next link:
https://developer.mozilla.org/en-US/docs/Web/API/MediaSession
This is a little example:
var trackElement = document.getElementById("track_el");
// Make sure browser has Media Session API available
if ('mediaSession' in navigator) {
// Access to Media Session API
var ms = navigator.mediaSession;
// Create track info JSON variable
var trackInfo = {};
// Set track title
trackInfo.title = "Polaris";
// Set artist name
trackInfo.artist = "Downtown Binary & The Present Sound";
// Set album name
trackInfo.album = "Umbra";
// Set album art (NOTE: image files must be hosted in "http" or "https" protocol to be shown)
trackInfo.artwork = [
{ src: 'https://antonyhr.neocities.org/temp/polaris/polaris_album_art_96.jpg', sizes: '96x96', type: 'image/jpg' },
{ src: 'https://antonyhr.neocities.org/temp/polaris/polaris_album_art_128.jpg', sizes: '128x128', type: 'image/jpg' },
{ src: 'https://antonyhr.neocities.org/temp/polaris/polaris_album_art_192.jpg', sizes: '192x192', type: 'image/jpg' },
{ src: 'https://antonyhr.neocities.org/temp/polaris/polaris_album_art_256.jpg', sizes: '256x256', type: 'image/jpg' },
{ src: 'https://antonyhr.neocities.org/temp/polaris/polaris_album_art_384.jpg', sizes: '384x384', type: 'image/jpg' },
{ src: 'https://antonyhr.neocities.org/temp/polaris/polaris_album_art_512.jpg', sizes: '512x512', type: 'image/jpg' }
];
// Then, we create a new MediaMetadata and pass our trackInfo JSON variable
var mediaMD = new MediaMetadata(trackInfo);
// We assign our mediaMD to MediaSession.metadata property
ms.metadata = mediaMD
// And that will be all for show our custom track info in Windows (or any supported) Media Player Pop-Up
// If we need to customize Media controls, we must set action handlers (NOTE: It's not necessary to add all action handlers).
ms.setActionHandler('play', function() {
trackElement.play();
var trackInfoEl = document.getElementById("track_info_el");
trackInfoEl.textContent = "Track is playing.";
});
ms.setActionHandler('pause', function() {
trackElement.pause();
var trackInfoEl = document.getElementById("track_info_el");
trackInfoEl.textContent = "Track is paused.";
});
ms.setActionHandler('stop', function() { /* Code excerpted. */ });
ms.setActionHandler('seekbackward', function() { /* Code excerpted. */ });
ms.setActionHandler('seekforward', function() { /* Code excerpted. */ });
ms.setActionHandler('seekto', function() { /* Code excerpted. */ });
ms.setActionHandler('previoustrack', function() { /* Code excerpted. */ });
ms.setActionHandler('nexttrack', function() { /* Code excerpted. */ });
} else {
console.warn("Your browser doesn't have Media Session API");
}
body {background: #181818;}
p {color: #fff; font-family: "Verdana", "Roboto", "Century Gothic";}
<audio id="track_el" controls autoplay src="https://firebasestorage.googleapis.com/v0/b/tempfiles-2912.appspot.com/o/polaris_clip.mp3?alt=media&token=bcfc245e-dc89-4046-b287-b99046c786bf" type="audio/mp3"></audio>
<p id="track_info_el">Track is playing.</p>
<p>Once audio is playing, see Media Player Pop-Up.</p>
I'm not pretty sure how you can add Lyrics to Media Player Pop-Up, but I think everything else is covered ✅.
If this answer was helpful, please, don't doubt to vote up.
Have a nice coding :D

Telegram: Sen photo into a message without showing the photo link with Telegraf (NodeJs)

I'm on a channel that sends messages that contains a text, with a link (that link has not an image) and an image (tip product from amazon):
I tried with this code and it's similar:
bot.telegram.sendMessage('mychannel', `Hello https:/path/to/image.jpg`)
And it works it similar, but it remains the link. SO how can i put that way with image preview but not the link?
Thank you
One workaround(trick) would be to insert the link but use an empty character unicode (like from https://emptycharacter.com/)
Here is an example (I inserted the photo URL with an empty character)
some sample code to get you started:
const Telegraf = require("telegraf");
const bot = new Telegraf(" ... ");
const CHAT_ID = ... ;
function getHiddenLink(url, parse_mode = "markdown") {
const emptyChar = "‎"; // copied and pasted the char from https://emptycharacter.com/
switch (parse_mode) {
case "markdown":
return `[${emptyChar}](${url})`;
case "HTML":
return `${emptyChar}`;
default:
throw new Error("invalid parse_mode");
}
}
// Option 1: sending with MARKDOWN syntax
bot.telegram.sendMessage(
CHAT_ID,
`
some test text in markdown
${getHiddenLink("https://i.stack.imgur.com/TPKR5.png", "markdown")}
`,
{
parse_mode: "markdown",
}
);
// Another option: sending with HTML syntax
bot.telegram.sendMessage(
CHAT_ID,
`
some test text in HTML
${getHiddenLink("https://i.stack.imgur.com/TPKR5.png", "HTML")}
`,
{
parse_mode: "HTML",
}
);
Here we just create a new function getHiddenLink() that accepts the URL and parse_mode (HTML or markdown) and just craft a new URL representation with the empty character as the link-text and return it.
There is no way to send a preview without a link. You can try to have some by your own telegram account and you will see it is impossible.
Instead of preview, add some caption to photos.

How can I identify the particular attachments when I click on a button in cards?

I am working on a bot project. How can I implement a feature like this?
Here when I click the Show Me button of Search Flights its providing flights related information and when I am click the show me button of Search Hotel its providing the hotel related information.
In my current working bot when I am click reserve now(like in the above figure show me button) I am getting the JSON response without information of selected attachment like this below figure.
So, how can I do the same thing in my bot?
For that I am write the below lines of code in my Project
enter code here
place=activity.text(with in the place i am passing the city name)
MessagesController.hotelsList = await PropertyService.getHotelsList(place, DateTime.Now);
var hotellist = MessagesController.hotelsList;
Activity replyToConversation = message.CreateReply("Welcome to **Hotel Reservation Bot**." + "(Hi)");
replyToConversation.Recipient = message.From;
replyToConversation.Type = "message";
replyToConversation.Attachments = new List<Attachment>();
foreach (var list in hotellist.SearchResults)
{
List<CardAction> cardButtons = new List<CardAction>();
CardAction plButton = new CardAction()
{
Value ="Reserve Now",
Type = "imBack",
Title = "Reserve Now"
};
cardButtons.Add(plButton);
ThumbnailCard plCard = new ThumbnailCard()
{
Title = i + "." + "Name:" + list.Property.CallingDisplayName,
Subtitle = "Location:" + list.Property.Location.City,
Images = cardImages,
Buttons = cardButtons
};
Attachment plAttachment = plCard.ToAttachment();
replyToConversation.Attachments.Add(plAttachment);
i++;
}
replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
await context.PostAsync(replyToConversation);
It would be best if you'd show your code, but the general idea is that the text on the button and what that button actually sends to the chat must be different:
var button = new CardAction() {
Title = "Show me",
Value = "Show restaurant #" + restaurantID,
Type = ActionTypes.imBack
};
When the user clicks it, they will see "Show me" in chat, but actually your application will receive "Show restaurant #35" in Activity.Text.

Different listeners for each notification

Here's my code below,
var opt1 = {type: "basic",title: "Teva Noti1",message: "Don't click me!",iconUrl: "icon-phone.png"}
chrome.notifications.create("noti1",opt1,function(notificationId){
chrome.notifications.onClicked.addListener(function(notificationId){
alert("test1")
})
});
var opt2 = {type: "basic",title: "Teva Noti2",message: "Don't click me!!!",iconUrl: "icon-phone.png"}
chrome.notifications.create("noti2",opt2,function(notificationId){
chrome.notifications.onClicked.addListener(function(notificationId){
alert("test2")
})
});
I want to do different actions for each notifications. In my code, both alerts popped when I clicked any one of the notifications
You can try adding just one listener to the notifications and check which one was clicked in the listener:
chrome.notifications.onClicked.addListener(function(notificationId){
if (notificationId == "noti1"){
alert("test1");
} else if (notificationId == "noti2"){
alert("test2");
});

Sent a picture in a chatbot using botframework

I have a chatbot using the botframework of Microsoft, with my webapp running the chatbot on Azure. How can I return a picture as an answer to a message. We have clients using Skype, Messenger and KiK
Take a look at the docs section on image and file attachments
replyMessage.Attachments.Add(new Attachment()
{
ContentUrl = "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png",
ContentType = "image/png"
});
Or as JSON:
{
"attachments": [
{
"contentType": "image/png",
"contentUrl": "https://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png"
}
]
}
You can also send Rich Cards:
replyMessage.Attachments = new List<Attachment>();
replyMessage.Attachments.Add(new Attachment()
{
Title = "Bender",
TitleLink = "https://en.wikipedia.org/wiki/Bender_(Futurama)",
ThumbnailUrl = "http://www.theoldrobots.com/images62/Bender-18.JPG",
Text = "Bender Bending Rodríguez, commonly known as Bender, is a main character in the animated television series Futurama.",
FallbackText = "Bender: http://www.theoldrobots.com/images62/Bender-18.JPG"
});

Resources