trying to create a extremely simple chrome extension, but need some help.
Purpose: When I click the extension icon, URL of existing tab must be forwarded to telegram. This can be done via a HTTPS call like https://api.telegram.org/bot123456:xxxxxxxxxxxxxxxxxxxxxx/sendMessage?chat_id=12345678&text=https://activetab.url
Single extension button, when clicked:
Grab URL of active link
Post http enriched with link url grabbed in previous step
No security concerns, I want to install the extension in developer mode only in my own browser.
Goldplated option would be to let the user specify the bot, the token & recipient id in settings of the app.
Thx for any feedback
It should only take a few lines of code.
I assumed that the http request is of type: "GET".
If not, you have to modify the fetch command according to Telegram specifications.
//manifest.json
{
...
"background": {
"service_worker": "background.js"
},
"action": {
"default_icon": { // optional
"16": "images/icon16.png", // optional
...
},
"default_title": "Click Me" // optional
},
"permissions": ["tabs"]
...
}
//background.js
chrome.action.onClick.addListener(t => fetch('https://api.telegram.org/bot123456:xxxxxxxxxxxxxxxxxxxxxx/sendMessage?chat_id=12345678&text=' + tab.url))
Related
I want to get page status codes like 40* or 30*. Firefox extension can get status when page loaded, when content_script.js executed. But content script not executed when page not loaded (3xx or 4xx errors).
How to check that the tab with a specific URL is not loaded?
To do this you need to handle the onHeadersReceived event in your background.js. You can refer the documentation here.
browser.webRequest.onHeadersReceived.addListener(function(details){
if(!details.initiator)
{
alert(details.url+" "+details.statusCode);
}
},
{
urls: ["<all_urls>"]
},
["responseHeaders", "blocking"]);
In your manifest.json you need to add
"permissions": ["webRequest","webRequestBlocking","<all_urls>"],
I have written a custom Slash command that takes in a query from the user and returns an image.
The Server side which receives the Slash command retrieves the query from the user, and forms the Image URL http://example.com/file1.png and it sends back the response as <http://example.com/file1.png>. This is shown as a link in the response and is not unfurled. What could be the problem?
I even tried the following:
1) I sent back a JSON payload as given below:
{
"text":"http://example.com/file1.gif","unfurl_media":true
}
But that displayed the link again and did not unfurl it.
2) I tried
{
"text":"<http://example.com/file1.gif>","unfurl_media":true
}
But same results.
What could be the problem? Do I absolutely need a incoming webhook integration and send the message there ?
Did it work the first time, or had the URL previously been unfurled?
Slack will only automatically unfurl a URL once per hour in a given channel. If a user manually posts the URL and it is not unfurled because of this limit they will get an ephemeral message from SlackBot about it, however the unfurl just silently fails for slash commands or webhooks. I've hit this before in testing and had to make sure to change either the URL or the channel to verify things are working.
You should not need a manual attachment or a webhook or even the unfurl_media flag in the response (it's on by default for messages posted via webhooks/slash command).
I was having a similar issue with slash commands returning the text of my image url.
What you need to change is to use an object with an image_url for your image, and put that inside an attachments array.
Below is an example that returns the link of the image as text and the image itself.
{
"parse": "full",
"response_type": "in_channel",
"text": "http://example.com/file1.png",
"attachments":[
{
"image_url": "http://example.com/file1.png"
}
],
"unfurl_media":true,
"unfurl_links":true
}
{
"parse": "full",
"text": "http://example.com/file1.png",
"attachments":[
{
"image_url": "http://example.com/file1.png"
}
],
"unfurl_media":true,
"unfurl_links":true
}
I'd like to share a CloudKit asset in the public database with people who aren't using my app. From the CKAsset class, there's only a fileURL property, which points to a local file, so no URL given.
On the documentation for CloudKit Web Services, however, there is a "referencing existing assets" request, which in its' response gives a downloadURL to the asset file.
Calling this from my app gives me a 421 status code, which is described in documentation as "AUTHENTICATION_REQUIRED", as it requires a ckSession parameter to be given, which is a "session identifier of an authenticated user". It also passes a redirectURL, where a user can type in their iCloud login, and then be re-directed back to the web application, now with a session identifier.
Opening this URL inside the app didn't immediately return the session identifier, but instead expected the user to go through the login process in a browser, before receiving their session ID.
This seems totally off-track, and the wrong thing to be doing. I'm certainly not going to make my users log in to iCloud through a web interface. The only thing missing for that CloudKit Web Services url is the session ID. Is there a way for me to get that using the CloudKit framework? Or is there another way for me to find out this file's URL?
If you are using Apple's official CloudKit.js, here is the code to configure your CloudKit access:
window.addEventListener('cloudkitloaded', function() {
console.log('Cloudkit loaded');
CloudKit.configure({
locale: 'en-us',
containers: [{
containerIdentifier: 'iCloud.com.getYoursInXcode',
apiTokenAuth: {
apiToken: 'getThisInCloudkitDashboardApiAccess',
persist: true //Set cookie
},
environment: 'production'
}]
});
// Do your thing here
})
If you are fetching records in your backend, it is still better to get your API token instead of using the Server-To-Server process.
For example, query records in GO, to fetch a record, compose your request body like this
sampleRequest = []byte('{
"resultsLimit":"4",
"desiredKeys": ["recordTitle","recordDescription"],
"query": {
"recordType": "myRecord",
"sortBy": {
"fieldName": "rank",
"ascending": true
}
}
}')
And send it to the following Url
http.NewRequest("POST", ""https://api.apple-cloudkit.com/database/1/iCloud.com.yourIdentifier/production/public/records/query?ckAPIToken=YOURTOKEN", bytes.NewBuffer(RequestBody))
I have a SharePoint provider hosted app. The Chrome control is configured and seems to be working correctly. I've configured a single settings with the following options:
var options = {
"appTitle": document.title,
"appStartPage": "/?" + queryString,
"onCssLoaded": "QuotationApprovalsApp.chromeLoaded();",
"siteTitle": "Test",
"settingsLinks": [
{
"linkUrl": "/Test?" + queryString,
"displayName": "Test"
}
]
};
The linkUrl goes to a test page in my application. This works and looks fine. Clicking the back button in the browser results in this:
Any idea why back button causes this? In IE developer toolbar, I see the following error:
404 error
Key Value
Request GET /__browserLink/requestData/0055c17ab05b44599accaf6714a5604b?version=2 HTTP/1.1
Adding SPHostTitle to the Query string in AppManifest fixed this issue:
Is there any way to fetch user’s phone number in Firefox OS?
If so, any help would be appreciated.
According to Mozilla's app permissions page, there is an permission called "phonenumberservice" but there is no information about it. Anyway, the permision is listed under the "Internal (Certified) app permissions", which means that, when available, it can only be used by "system-level apps and default apps created by Mozilla/operators/OEMs".
With Firefox 2.0 you should be able to use Mobile Identity API:
https://wiki.mozilla.org/WebAPI/MobileIdentity
https://bugzilla.mozilla.org/show_bug.cgi?id=1021594
I believe the permission is:
"permissions": {
"mobileid": {} }
And it is privileged.
So, as #Jason said, the Mobile Identity API provides this capability, and not just for certified, but for privileged applications. So it is no longer just for OEMs.
The Mozilla Wiki site shows the API:
dictionary MobileIdOptions {
boolean forceSelection = false;
};
partial interface Navigator {
Promise getMobileIdAssertion(optional MobileIdOptions options);
};
The site also provides a sample code skeleton for this:
function verifyAssertion(aAssertion) {
// Make use of the remote verification API
// and return the verified msisdn.
// NB: This is necessary to make sure that the user *really* controls this phone number!
}
// Request a mobile identity assertion and force the chrome UI to
// allow the user to change a possible previous selection.
navigator.getMobileIdAssertion({ forceSelection: true })
.then(
(assertion) => {
verifyAssertion(assertion)
.then(
(msisdn) => {
// Do stuff with the msisdn.
}
);
},
(error) {
// Process error.
};
);
For this to work, you need to add the mobileid permission in the manifest file, for example like this (I made up the description):
"permissions": {
"mobileid": {
"description": "Required for sending SMS for two factor authentication",
"access": "readonly"
}
}
PS: I made this answer, because most answers are outdated, and the one that isn't, does not contain all useful information.
References:
App Manifest Documentation
Firefox Remote Verification