I am trying to send a message from Google Apps Script to Slack via a Webhook URL that works great, but I can't figure out how to send a highlighted or selected user in that text. For example '#UsernameTest how are you?' is something I want to send to a person or channel, but it doesn't work. I figured out that to highlight the channel i.e. send '#Channel' I just needed to write , but that is not what I want. I tried <#UserID> but it still didn't work. (I Received the UserID by using inspector tool on the web-version of Slack on the user.)
The Slack API docs helped some but still have problems.
Here is the code I'm using, thank you.
var SLACK_URL = 'https://hooks.slack.com/services/...
function sendSlackMessage(text) {
var slackMessage = {
text: "#UsernameTest how are you? and all you guys <#Channel>?"
};
var options = {
method: 'POST',
contentType: 'application/json',
payload: JSON.stringify(slackMessage)
};
UrlFetchApp.fetch(SLACK_URL, options);
}
The correct format for sending user mentions is <#[user-id]>
And for channel pings the syntax is <!channel> or <!here>.
e.g. to send a mention to a user with user ID U1234567 you need to sent the string:
<#U12345678> how are you? and all you guys <!channel>?"
For more information on how to link users and channel see the documentation.
Note that #username is being phased out and should no longer be used. For more details see "A lingering farewell to the username" from Slack.
Seems that you have 3 " in that line:
text: "#UsernameTest how are you? and all you guys "<#Channel>?"
Related
I tried to login my account by using UrlFetchApp, when I ran script manually, everything worked well. But when I set trigger to run automatically, it returned "error_need_ivs". I have no idea what it is and how to fix. please help me. Below is my code
function login() {
var data = {
'username':'username',
'password_hash':'password',
}
var option = {
muteHttpExceptions: true,
"method" : "POST",
"payload" : data,
}
var url = 'my url'
var res = JSON.parse(UrlFetchApp.fetch(url,option).getContentText());
Logger.log(res) //returned error_need_ivs when I set trigger but worked well when I ran script manually
}
UPDATE : This picture show the result after scripting executed by trigger
From the new screenshot shared I can see no Exceptions were thrown, which means the error logged error_need_ivs certainly comes from the response of the HTTP request rather than an issue with Apps Scripts.
Regarding why it works when calling the affected function manually and why it doesn't worked when invoking it via timed-trigger, I believe what #Tanaike suggested to make sense, maybe the affected endpoint is not prepared to receive IPv6 requests or require more data when doing so.
I'd suggest checking the documentation for the endpoint you are making the request for to help identify what might be causing this behavior.
Alternatively, I'd also suggest to report it as an Issue on IssueTracker using this template. Make sure to include a full reproducible scenario when reporting it (including a working endpoint).
I've been researching this and cannot find or understand some of the solutions so i'm hoping to get some help here. I'm using Asp.net and building an application that needs to use a bible api. I like the two listed in the question. Every time I call esvapi it comes back successful, but I cannot view the data. I get an error in the console.
XMLHttpRequest cannot load http://www.esvapi.org/v2/rest`/passageQuery?key=8834092f0c58fcda&passage=James2. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:59324' is therefore not allowed access.`
I've seen other with this error and I have questions.
If I'm understanding this correct I get this because the server is preventing me from seeing the data for security purposes. Maybe even the browser( this is not just a chrome issue) problem. So if I need to add a info to the response header from Angularjs to stop this how is that done. Anyone with experience?
Would I need to contact anyone to be able to prevent the server from responding this way...I doubt this, but thought I would ask. I already have valid api key.
the bible.org website api key is confusing to apply to my code. on esvapi i just add a header with key: "keypass" and I only have the CORS issue. But with bible.org I can't figure out how to implement the api key and password. see below... Do I say token:key: username. If i put the api in the browser I get a popup to add username and password. the username is my key and the password is ignored. I tried putting in username as key, but that didn't cut it. Regardless I need to fix the CORS issue and add info to response headers to see response data.
$scope.search = function() {
return $http.get("http://www.esvapi.org/v2/rest/passageQuery?&passage=" + $scope.bo + $scope.chap, {
headers: {
"key?token?orusername?": "",
///thought i saw someone do this...don't know if this is right
"Access-Control-Expose-Headers": "Content-Disposition",
}
}).success(function (data, status, headers, config) {
$scope.book = data.Book;
$scope.chapter = data.Chapter;
$scope.output = data.Output;
}).error(function (data, status, headers, config) {
$scope.message = "Oops... something went wrong";
});
Any input would be helpful. Thanks!
I actually have a bible api working...just a version that I don't like and there is not another version on that webites api.
Change the get $http.get call to $http.jsonp and hope it works. You're using cross-site scripting. Sometimes you can get away with a JSONP call in these cases and sometimes you can't.
I am sending push notifications to my Android phone. I want these notifications grouped so my notification list does not get flooded.
According to the documentation messages from the same 'source' get grouped but on my phone the messages always show up ungrouped.
I call the push API from a Google Apps script and have tried setting source_device_iden, source_user_iden and notification_tag when I call the push API. None of these seem to make any difference.
How can I get the pushmessages to be grouped on my phone?
Google Apps script code
function pushNoteToPhone(title, body) {
var digest = "Basic "+Utilities.base64Encode(PUSH_BULLET_TOKEN+":");
var options = {
"method" : "post",
"payload" : {
"device_iden" : MYPHONE_ID,
"type" : "note",
"title" : title,
"body" : body,
"source_device_iden" : <device id>,
"notification_tag": "tag1",
},
"headers" : {
"Authorization": digest
}
};
var push_bullet_url = "https://api.pushbullet.com/v2/pushes";
UrlFetchApp.fetch(push_bullet_url, options);
}
The easiest way to do this (admittedly it should be easier) is to create an OAuth Client and then send using an access token for that oauth client. That way the pushes will all appear to come from that client instead of you. This is how IFTTT and Zapier work on Pushbullet.
Here's how to setup an oauth client: https://docs.pushbullet.com/#oauth
To get an access token you can use the "oauth test url" on the create client page, you will end up with an access token in the URL once you approve access. Use that access token instead of your normal one and the pushes will appear to come from the client instead of you.
Don't know how you are trying to update the notification but without the code, my guess is that you are trying to pass a new Notification ID to each notification being sent to the device. However, please take a look here and look under, "Updating Notifications". As explained in the documentation, by passing the same ID to each notification it will either group these notifications on the device or create a new one in case the old one has been dismissed.
I am trying to PATCH (partially update) Firebase records (firebase.com). This works perfect outside of Google Apps Script using PATCH. GAS is not supporting PATCH and I tried X-HTTP-Method-Override without success. Using GAS with X-HTTP-Method-Override renders the same result as a standard GET. There is no security on my test database. No log-in is required.
var myPayload = "{\"WSD124\" : {\"auction\" : {\"stockno\" : \"ESD124\", \"highbid\" : \"240\"}}}";
var myURL = "https://mydatabase.firebaseio.com/auctions/.json";
var options = {
headers: {
"X-HTTP-Method-Override" : "PATCH"
},
method: "POST",
payload: myPayload
};
var oResponse = UrlFetchApp.fetch(myURL,options);
A quick update for those coming back to this old thread - we now support X-HTTP-Method-Override headers on all REST API calls, so this should now work
UPDATE
This is now supported. See Chris Raynor's answer.
OLD ANSWER
We don't currently support X-HTTP-Method-Override though we are considering it. For now you'll likely have to do a PUT with the whole record. Give us an email at support#firebase.com if this is significantly blocking you.
after reading the oauth documentation on box's website, I understand the steps to get access_token and refresh_token, which requires authorization_code.
step1: send Get request to https://www.box.com/api/oauth2/authorize?response_type=code&client_id=CLIENT_ID&state=authenticated&redirect_uri=https://www.appfoo.com
step2: after entering credentials of box in browser and then click the "Allow" button, redirect to the specified redirect_uri with state=authenticated&code=AUTHORIZATION_CODE
step3: now with the AUTHORIZATION_CODE in the redirect url from step2, getting access_token can be done programmatically, by sending POST request to https://www.box.com/api/oauth2/token with AUTHORIZATION_CODE, client_id, client_secret in body and then parsing the returned json response.
My question is: is it possible to programmatically do step1 and step2 instead of via browser?
thank you very much!
The current OAuth 2 flow requires the user to go through the browser and can't be done programmatically.
It is possible, just imitate every form with cURL and on second step post cookies.
First time you will need 3 requests, next time only one (if refresh_token isn't expired, otherwise 3 again)
The point about imitating the browser transactions is a good one but instead of using cURL you would want to use a higher level tool like mechanize (available for ruby, perl and python). It will handle the cookies for you and can programatically traverse forms and links. Good for page scraping and writing scripts to order hot concert tickets from TicketMaster too!
If you have the authorization code, you then should be able to get the OAuth Token(access_token, refresh_token) via SDK, correct?
In response to aIKid, this is what I first do to get a BoxClient
BoxClient client = new BoxClient(clientId, clientSecret);
Map<String,Object> authToken = new HashMap<String,Object>();
authToken.put("exprires_in","3600");
authToken.put( "token_type","bearer");
authToken.put("refresh_token", clientRefreshToken);
authToken.put("access_token",clientAccessToken);
BoxOAuthToken oauthToken = new BoxOAuthToken(authToken);
client.authenticate(oauthToken);
return client;
Then, I have this to create a new user,
BoxUser createdUser = new BoxUser();
BoxUserRequestObject createUserRequest = BoxUserRequestObject.createEnterpriseUserRequestObject("someEmail.domain.com", "test user");
createdUser = client.getUsersManager().createEnterpriseUser(createUserRequest);
Now I'm trying to figure out how to do the RUD part of my CRUD operations on users and groups.