How to create Chrome notification for my changes in website? - google-chrome-extension

How to create google chrome extension with a notification for every change in my website page ?

If your site has RSS feed, you can do something like this (only new pages):
Get and parse RSS feed using jQuery:
$.get('http://yoursite.com/rss', function(data) {
$(data).find('item').each(function() {
var url_news = $(this).find('link').text();
var news_id = $(this).find('id').text();
var descr = $(this).find('title').text();
});
});
Show Notify using Chrome Notification
https://developer.chrome.com/extensions/notifications
var title = "Title";
var notification = webkitNotifications.createNotification(img, title, descr);
notification.onclick = function() {
chrome.tabs.create({url: url_news}, notification.cancel());
chrome.windows.getLastFocused(null, function(win){
if(win.state=="minimized"){
chrome.windows.update(win.id, {state:"normal", focused:true});
}
});
};
notification.show();
When updated your rss feed, chrome extension will display notifications

Related

How to trigger a customised welcome message from Dialogflow bot using kommunicate.io?

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 can detect whether its mobile or desktop but further i want to detect that which mobile browser is accessing URL?

I am working on mediarecorder so I stuck at detecting the mobile browser(for iphone also) so that I can open url forcefully in chrome
var URL = window.location.href;
var RedirectFlag = getUrlVars()["redirectflag"];
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
if(RedirectFlag=='1')
{
function();
}
else
{
URL = URL.replace("http://123", "intent://123");
URL = URL + "&redirectflag=1#Intent;scheme=http;package=com.android.chrome;end";
window.location.href = URL;
}
}

How to copy postman history from chrome app to native app?

Since Google is now ending the support for chrome apps. Recently Postman deprecated their chrome app and introduced a native app.
I am in the process of switching from postman chrome app to native app.
How do I copy the history from my chrome app to native app. Sync doesn't work.
There is a option to export data but that doesn't export the history.
Any Ideas?
So while searching for this I came across this post which is very helpful.
Thanks to stephan for sharing this code.
Follow these steps to copy your history from chrome app to native app.
//In Chrome DevTools on the background page of the Postman extension...
//A handy helper method that lets you save data from the console to a file
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
//Common error reporting function
function reportError(){
console.error('Oops, something went wrong :-(');
}
//Open the database
var dbReq = indexedDB.open('postman')
dbReq.onerror = reportError;
dbReq.onsuccess = function(){
var db = dbReq.result;
//Query for all the saved requests
var requestReq = db.transaction(["requests"],"readwrite").objectStore('requests').getAll();
requestReq.onerror = reportError;
requestReq.onsuccess = function(){
var requests = requestReq.result;
//Dump them to a file
console.save(JSON.stringify(requests), 'postman-requests-export.json')
console.info('Your existing requests have been exported to a file and downloaded to your computer. You will need to copy the contents of that file for the next part')
};
};
//Switch to standalone app and open the dev console
//Paste the text from the exported file here (overwriting the empty array)
var data = []
//Enter the guid/id of the workspace to import into. Run the script with this value blank if you need some help
// finding this value. Also, be sure you don't end up with extra quotes if you copy/paste the value
var ws = '';
//Common error reporting function
function reportError(){
console.error('Oops, something went wrong :-(');
}
//Open the database
var dbReq = indexedDB.open('postman-app')
dbReq.onerror = reportError;
dbReq.onsuccess = function(){
var db = dbReq.result;
if(!data.length){
console.error('You did not pass in any exported requests so there is nothing for this script to do. Perhaps you forgot to paste your request data?');
return;
}
if(!ws){
var wsReq = db.transaction(["workspace"],"readwrite").objectStore('workspace').getAll();
wsReq.onerror = reportError;
wsReq.onsuccess = function(){
console.error('You did not specify a workspace. Below is a dump of all your workspaces. Grab the guid (ID field) from the workspace you want these requests to show up under and include it at the top of this script');
console.log(wsReq.result);
}
return;
}
data.forEach(function(a){
a.workspace = ws;
db.transaction(["history"],"readwrite").objectStore('history').add(a);
});
console.log('Requests have been imported. Give it a second to finish up and then restart Postman')
}
//Restart Postman
Note :
1.To Use DevTools on your chrome app you will need to enable following flag in
chrome://flags
2.Then just right click and inspect on your chrome postman app.
3.To User DevTools on your native app ctrl+shift+I (view->showDevTools)

Chrome inapp purchase test

I'm trying to implement an inapp purchase for my Chrome Extension. I have followed the guide on https://developer.chrome.com/webstore/payments-iap, added 1 buyable item and implemented following code on an onclick event:
google.payments.inapp.getSkuDetails({
'parameters': {'env': 'prod'},
'success': onSkuDetails,
'failure': onSkuDetailsFail
});
var onSkuDetails = function (response) {
console.log("onSkuDetails", response);
/*var products = response.response.details.inAppProducts;
var count = products.length;
for (var i = 0; i < count; i++) {
var product = products[i];
addProductToUI(product);
}
getLicenses();*/
}
var onSkuDetailsFail = function(result){
console.log("onSkuDetailsFailed", result);
}
But every time I click it, I get
onSkuDetailsFailed > "INVALID_RESPONSE_ERROR"
I have added the buy.js and changed some permissions, but still don't see where the problem might be.
Do note, that I'm testing this extension locally and not from the Chrome webstore using my own account and a friend's account which I included as testperson on the dashboard.

Default Media Receiver limitations

Can I use the Default Media Receiver to display a web page or an HTML5 app? Using Javascript in the Chrome browser, I have no problem sending a single png image (content type image/png) to the Chromecast but it fails if I specify an html link (content type text/html). session.loadMedia will fire the error handler and e.code/e.description reports session_error/LOAD_FAILED. I used Google's home page for my test:
//var currentMediaURL = "https://www.google.com/images/srpr/logo11w.png";
//var currentMediaType = "image/png";
var currentMediaURL = "https://www.google.com";
var currentMediaType = "text/html";
function startApp()
{
var mediaInfo = new chrome.cast.media.MediaInfo(currentMediaURL, currentMediaType);
var request = new chrome.cast.media.LoadRequest(mediaInfo);
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError);
};
I think you need to have custom receiver, just have it run your code accordingly...

Resources