Discord.net sending direct message(PM) to the command runner person - discord.net

So i am working on a Discord bot, and i wanted something like almost every bot uses: when the player typed a command (!help) then it will send him the cmds. Anybody can help?

Using Discord.Net 1.0 it is very simple :
await Context.User.SendMessageAsync("Message");
You can also embed a message like this :
var EB = new EmbedBuilder();
EB.WithTitle("Secret Commands");
EB.WithDescription("!command \n" + "!anothercommand");
await Context.User.SendMessageAsync("", false, EB);

Related

bot.telegram.getChat does not return the message of a specific user

I am trying to setup my bot so that it will 'listen' to a specific user and print out any incoming message.
I have already setup a bot in telegram using BotFather. This is what I have so far
const { Telegraf } = require('telegraf')
const bot = new Telegraf('my_bot_token_here');
bot.telegram.getChat(Chat_Id).then(function(chat) {
console.log('chat info', chat);
});
The object does not contain the user message.
Any advice on this is appreciated.
Yes, absolutely. You need to check the 'from' field in the message before executing your logic.
Telegram API

Google Apps Script: Salesforce API Call

Just finished breakfast and already hit a snag. I'm trying to call the salesforce REST api from my google sheets. I've written a working script locally in python, but converting it into JS, something went wrong:
function authenticateSF(){
var url = 'https://login.salesforce.com/services/oauth2/token';
var options = {
grant_type:'password',
client_id:'XXXXXXXXXXX',
client_secret:'111111111111',
username:'ITSME#smee.com',
password:'smee'
};
var results = UrlFetchApp.fetch(url, options);
}
Here is the error response:
Request failed for https://login.salesforce.com/services/oauth2/token
returned code 400. Truncated server response:
{"error_description":"grant type not
supported","error":"unsupported_grant_type"} (use muteHttpExceptions
option to examine full response) (line 12, file "Code")
Mind you, these exact parameters work fine in my local python script (putting the key values inside quotations).
Here are the relevant docs:
Google Script: Connecting to external API's
Salesforce: REST API guide
Thank you all!
Google's UrlFetchApp object automatically defaults to a GET request. To authenticate, you have to explicitly set in the options the method "post":
function authenticateSF(){
var url = 'https://login.salesforce.com/services/oauth2/token';
var payload = {
'grant_type':'password',
'client_id':'XXXXXXXXXXX',
'client_secret':'111111111111',
'username':'ITSME#smee.com',
'password':'smee'
};
var options = {
'method':'post',
'payload':payload
};
var results = UrlFetchApp.fetch(url, options);
}

Google login in PHP backend and JS frontend

Front end is 100% JS. User click on sign in button and an authResult['code'] is received and send via ajax to localhost/api/user/login which has the following content:
$code = $data['code'];
require_once 'Google/Client.php';
$client = new Google_Client();
$client->setClientId('xxxxxx');
$client->setClientSecret('xxxxx');
$client->setRedirectUri('http://localhost:8080');
$client->setScopes('email'); //Why do I need this? I already set scope in JS.
$client->authenticate($code); //It fails here. with no error. just 400 bad request.
$token = json_decode($client->getAccessToken());
$reqUrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' .
$token->access_token;
$req = new Google_HttpRequest($reqUrl);
$tokenInfo = json_decode(
$client::getIo()->authenticatedRequest($req)->getResponseBody());
//Check errors.
//Save user personal info in database
//Set login sessions
Why do I need to set scopes if I already set them in javascript?
Why is it failing when authenticate function is called? Im getting no erros.
Why do I need a setRedirectUri() when it is on the backend?
You don't need to set scopes in this case.
(see answer 3, but also): Check your client ID matches the one used in the Javascript, and that the client secret is exactly as in the console (no trailing/leading spaces).
Changing your redirecturi to 'postmessage' - this is the string used when the code was generated via the Javascript process.
You can also try manually constructing the URL and calling it with curl to make sure everything is as you expect: https://developers.google.com/accounts/docs/OAuth2WebServer#handlingtheresponse

Node.js - Reply to Instagram hub.challenge

Pretty new to Node.js. I'm working on a project where I need access to Instagram's subscription/streaming API. Stuck on the handshake authorization, where my server needs to reply with a challenge code sent by Instagram.
The code to get and log the challenge code:
var http = require('http'),
url = require ('url');
http.createServer(function (req, res) {
var parts = url.parse(req.url, true);
var parts = parts.query['hub.challenge'];
console.log(parts);
}).listen(8080, '0.0.0.0');
And the code to send the subscribe request to Instagram:
Instagram = require('instagram-node-lib');
Instagram.set('client_id', 'myClientID');
Instagram.set('client_secret', 'myClientSecret');
Instagram.set('callback_url', 'http://www.myLocalTunnelAddress/callback.js')
Instagram.media.subscribe({ lat: 48.858844300000001, lng: 2.2943506, radius: 1000 });
I can get the challenge code from Instagram's GET request, but have been working at this for a while and haven't been able to send it back. Does anyone have a suggestions as to how to do this? Thank you!
Check out this node.js library
https://github.com/mckelvey/instagram-node-lib/blob/master/lib/class.instagram.subscriptions.js
and how he implemented his handshake method:
https://github.com/mckelvey/instagram-node-lib/blob/master/lib/class.instagram.subscriptions.js

gmail contextual gadget makeRequest call responds with Internal Server Error

I am building a google contextual gadget in it i use the following code to load a page:
var params = {};
url = "http://example.com:2057/tasks/create";
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
params["OAUTH_SERVICE_NAME"] = "HMAC";
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
gadgets.io.makeRequest(url, function(response)
{
if (response.data && response.data.RedirectUrl)
HandleLogin(response.data.RedirectUrl);
else if(response.text)
{
showOneSection('main');
$('#main').append(response.text);
}
else
ShowDebug(response);
}, params);
The call does not reach my server. and when i try reaching the url in a browser it returns fast.
what can be the problem? how can i trouble shoot it?
Thanks
I finally found the problem.
when making a signed request you have to first obtain a consumer key + secret key.
see http://www.google.com/support/forum/p/apps-apis/thread?tid=31db71169fb6fc77&hl=en
you can do that here: https://www.google.com/gadgets/directory/verify
without the keys google is unable to sign the request (although one would expect a proper error message).