I have developed an extension and using Chrome API, which sends notification every 20 secs from background script
manifest.json
{
"name": "Test",
"description": "Test",
"manifest_version": 2,
"version": "0.1",
"chrome_url_overrides" : {
"newtab": "register.html"
},
"background": {
"scripts": ["background.js"]
},
"permissions": ["idle", "tabs", "gcm", "storage", "notifications"],
"icons": { "128": "gcm_128.png" }
}
background.js //sends notification
function messageReceived(message) {
var messageString = '';
if(message) messageString = message;
var nid = getNotificationId();
messageString = messageString + nid;
// Pop up a notification to show the GCM message.
chrome.notifications.create(nid, {
title: 'Kukdu Kuuu',
iconUrl: 'gcm_128.png',
type: 'basic',
message: messageString
}, function() {});
}
// Returns a new notification ID used in the notification.
function getNotificationId() {
var id = Math.floor(Math.random() * 9007199254740992) + 1;
return id.toString();
}
setInterval(function() {
console.log('running - ');
messageReceived('test notification ');
}, 20000);
It shows a notification when I am not on Chrome browser i.e when I am out of focus. But I don't receive notification when I am working on chrome.
When I run API, chrome.notifications.getAll(), I get the entire queue of IDs.
But, notifications are not getting displayed immediately on my system. What could be the problem? However, it works well on the windows machine.
This is an open issue in chrome.
Here is the link,
https://bugs.chromium.org/p/chromium/issues/detail?id=583746#
Important comments & summary,
This is definitely intentional but is is also a questionable decision.
Pro: * Won't interrupt immersive content such as movies with a
notification.
Con: * People use full screen to just browse as well,
esp. on Mac with the new fullscreen mode.
( Comment by dewittj#chromium.org )
And current behaviour of pushnotifications,
It queues received notification while in full-screen mode.
It shows all the notifications when user exits fullscreen mode or switch to some other app or window.
If the user exits the browser, the notifications is displayed on next browser restart.
Related
I am new to development in teams and botkit. There is a bot that is up and running on Teams.
I want to share a file generated by the bot to the user(send a file from bot to the user) on teams. I have read the Microsoft-teams document. According to which first step is to send a Message requesting permission to upload which I am able to complete successfully. Below is the code, I have used to show the card to the user to ask for permission.
controller.hears('download', ['message_received', 'direct_message', 'direct_mention'], function (bot, message) {
var reply = { text:"" ,attachments: [] }
var ticketObj = {
"contentType": "application/vnd.microsoft.teams.card.file.consent",
"name": "result.txt",
"content": {
"description": "Text recognized from image",
"sizeInBytes": 4348,
"acceptContext": {
"resultId": "1a1e318d-8496-471b-9612-720ee4b1b592"
},
"declineContext": {
"resultId": "1a1e318d-8496-471b-9612-720ee4b1b592"
}
}
}
reply.attachments.push(ticketObj)
bot.reply(message, reply)
})
According to the Microsoft-teams document, when the user will click on accept button, the bot will receive an Invoke activity with a location URL.
But, when I click on the accept, nothing goes to my bot. It shows the error message: "This card action is not supported".
How to provide support for this card action?
Adding answer from comment section for more visibility:
Issue is resolved now. The issue was of uploading the manifest.json.
To send and receive files in the bot, set the supportsFiles property
in the manifest to true. This property is described in the bots
section of the Manifest reference.
The definition looks like this, "supportsFiles": true. If the bot does
not enable supportsFiles, the features listed in this section do not
work.
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/bots-filesv4#configure-the-bot-to-support-files
Sample Link:
https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/56.teams-file-upload
I have just started creating a bot using dialogflow and kommunicate.io. So, I created a simple bot and integrated it with kommunicate and finally copied the kommunicatesettings script in my HTML page. I am able to get simple responses from the bot. But now I want to set a different welcome message for every HTML page. So can this be done using kommunicatesettings? I tried :
var kommunicateSettings = {"appId":"7519ee060abee2b532e8565aa0527ae","popupWidget":true,"automaticChatOpenOnNavigation":true,
"appSettings": {
"chatWidget": {
"popup": true
},
"chatPopupMessage": [{
"message": "Wanna ask something related to "+document.title+ "?",
"delay": 3000
}],
"text": {
"text": ["My welcome message!"]
}
}
};
var s = document.createElement("script"); s.type = "text/javascript"; s.async = true;
s.src = "https://widget.kommunicate.io/v2/kommunicate.app";
var h = document.getElementsByTagName("head")[0]; h.appendChild(s);
window.kommunicate = m; m._globals = kommunicateSettings;
})(document, window.kommunicate || {});
"text" in settings. But it is not able to do anything.
I want to show just the document title in the welcome message. So if some nodejs code for fulfillment can do that, it will be fine(document.title and window.location are not working in fulfillment code).
When a new conversation started and routed through the Dialogflow bot, Kommunicate triggers the Default Welcome Intent configured in Dialogflow console. However, You can customize a welcome message and set a different welcome message for your conversations dynamically. You have to create the events on the Dialogflow console and pass the event in customWelcomeEvent parameter. Below is the complete script :
(function (d, m) {
var kommunicateSettings = {
"appId": "your-app-Id",
onInit: function (status, data) {
if (status == "success") {
Kommunicate.updateSettings({ "customWelcomeEvent": "welcome_event_for_home_page" });
}
}
};
var s = document.createElement("script"); s.type = "text/javascript"; s.async = true;
s.src = "https://widget.kommunicate.io/v2/kommunicate.app";
var h = document.getElementsByTagName("head")[0]; h.appendChild(s);
window.kommunicate = m; m._globals = kommunicateSettings;
})(document, window.kommunicate || {});
You can update this setting dynamically when certain events occur on your website.
This setting will be applied to all the new conversations that started after the update i.e. The conversation started after the setting is updated will trigger the new welcome event.
Also, this setting can be used to show different welcome messages on different pages of your website.
I hope it helps.
you can enable and customise the default welcome intent in DialogFlow which Kommunicate triggers when a conversation is routed through the bot (for example upon page reload and the init of the Kommunicate plugin).
I am not sure you can customise the Welcome page for each page, at least not easily.
One approach to try is to pass some custom data to DialogFlow
var chatContext = {
"key1":"value1",
"key2":"value2"
}
Kommunicate.updateSettings({"KM_CHAT_CONTEXT":chatContext})
which is then passed on to the webhook
"originalDetectIntentRequest": {
"payload": {
"key1": "value1",
"key2": "value2"
}
}
I think it can eventually be used to personalise your welcome message.
I'm trying to write a chrome extension which intercepts network traffic and modify the data.
I would appreciate if someone can tell me exactly which API I should use for this and where I can find the documentation.
Make use of the webRequest API and have a look at their events.
Create a manifest with permissions activeTab to get permissions for the current tab on which you are on, and the url pattern you wish the extension to be enabled for. The webRequestBlocking permission needs to be set specifically for blocking and modifying traffic.
manifest.json
{
"manifest_version": 2,
"name": "network intercepter",
"description": "intercept/modify/block data",
"version": "1.0",
"background": {
"scripts": ["background.js"]
},
"host_permissions": [
"https://*.google.com/*"
],
"permissions": [
"activeTab",
"webRequest",
"webRequestBlocking"
]
}
Create a background script and start adding webRequest listener based on which actions you want to perform. This was useful for me when making those choices.
background.js
var onBeforeSendHeadersListener = function(details) {
// view request + headers to be send
console.log(details);
// block XMLHttpRequests by returning object with key "cancel"
if (details.type == "xmlhttprequest") {
return {
cancel: true
};
}
// modify the user agent of all script resources by changing the requestHeaders and then return an object with key "requestHeaders"
if (details.type == "script") {
for (var i = 0; i < details.requestHeaders.length; i++) {
if (details.requestHeaders[i].name == "User-Agent") {
details.requestHeaders[i].value = "I'm not a bot";
}
}
return {
"requestHeaders": details.requestHeaders
};
}
}
var onBeforeRequestListener = function(details) {
// all images will now be loaded from this location instead
// CAREFUL! CROSS ORIGIN REQUESTS WILL NOT BE BLOCKED WITH CHROME EXTENSIONS
if (details.type == "image") {
return {
"redirectUrl": "https://foo.bar/image.jpg"
};
}
}
chrome.webRequest.onBeforeSendHeaders.addListener(onBeforeSendHeadersListener, {
urls: ["https://*.google.com/*"]
}, ["requestHeaders", "blocking"]);
chrome.webRequest.onBeforeRequest.addListener(onBeforeRequestListener, {
urls: ["https://*.google.com/*"]
}, ["requestBody", "blocking"]);
Visit chrome://extensions and open the background page, and go to its console. Then visit https://google.com normally, you will see that all images are changed to their new location, the XHR's are blocked, and the script resources have their User Agent changed, and in the background console you will find the requests that were made.
I'm working on breaking my bot repo into 2 separate repos
A repo to purely handle bot logic
A repo to handle custom chat via directline
Currently , we have a feature where we can trigger the bot to start a specific dialog if its mentioned as a parameter in the URL. So something like
https://foo.com/?param=bar
would trigger the bar dialog
This is the code that handles it
function(userId, conversationId, params, token){
return new Promise((resolve, reject)=>{
var _directlineAddress = {
bot: {"id":config.BOT.ID, "name": config.BOT.HANDLE},
channelId: "directline",
serviceUrl: config.BOT.DIRECTLINE_URL,
useAuth: true,
user:{"id": userId},
"conversation": {"id": conversationId}
}
if(params.options){
var _re = /^\?(\w+)*=(\w+)*/
var _programType = _re.exec(params.options);
if (_programType[1] === "foo") {
var _dialogId = "*:/foo";
}
else {
var _dialogId = "*:/" + _programType[1];
}
} else {
var _dialogId = "*:/";
var _specialParams = {"sessionId":token};
}
bot.beginDialog(_directlineAddress, _dialogId, _specialParams, function(err){
else{
resolve();
}
});
})
};
Since i'm splitting the directline from the bot logic , i will no longer be having access to the bot object. therefore bot.beginDialog would not work here
Is there a way i can trigger the dialog by posting to the Directline API?
No. With Direct Line you will be able to send messages to the bot. I guess that a way to go here will be to define a convention message that you will send via Direct Line and that the bot logic will know that it will have to start a dialog based on it.
I have a background script in my Chrome Extension which downloads a file called install.bat from the extensions directory. That works perfectly. But when I want to call chrome.downloads.open(id); the following error gets thrown:
Unchecked runtime.lastError while running downloads.open: User gesture required
I have requested both permissions (["downloads", "downloads.open"]) in the manifest.json file which are required for this procedure.
Is there a workaround for this problem or even a plain solution?
So after I read the discussion #abielita mentioned in his comment, I found a solution for my problem. Notifications are now counted as User gesture again.
But being not able to open downloads automatically when the permission downloads.open is requested in the manifest makes this permission just useless.
So here is my solution (with wich I'm not really satisfied with, because the download doesn't open automatically) but it worked for me:
var downloadID = 123;
var nIcon = chrome.extension.getURL("icons/icon_48.png");
var nTitle = "My Extension - Client Installer";
var nMessage = "Please click the button below to run the installer.";
var nButtons = [{ title: "Run the installer..." }];
var nOptions = { type: "basic", iconUrl: nIcon, priority: 2, title: nTitle, message: nMessage, buttons: nButtons };
chrome.notifications.create("hello_world", nOptions, function (nIDa) {
chrome.notifications.onButtonClicked.addListener(function (nIDb, nButtonIndex) {
if (nIDb === nIDa) {
chrome.downloads.open(downloadID);
}
});
});