How to send message in muc group using ejabberd API? - ejabberd

I know using " ejabberdctl send_message groupchat user1#localhost room1#conference.localhost Sub Bodyyy" this command we can send group messages. But how to implement the same using HTTP API that ejabbered provides (here)? Is it possible? Else what are the other options which i can use?

Yes, see https://docs.ejabberd.im/developer/ejabberd-api/simple-configuration/ to enable the module. Or you can enable ejabberd_xmlrpc and send XML-RPC queries.

Related

Postgraphile "Only `POST` requests are allowed." error

I have Postgres running locally. I can access the database locally with psql postgres:///reviewapp and with \dt I can see a few tables.
If I run npx postgraphile -c "postgres:///reviewapp" I dont get any errors in the terminal:
PostGraphile v4.12.4 server listening on port 5000 🚀
‣ GraphQL API: http://localhost:5000/graphql
‣ GraphiQL GUI/IDE: http://localhost:5000/graphiql (RECOMMENDATION: add '--enhance-graphiql')
‣ Postgres connection: postgres:///reviewapp
‣ Postgres schema(s): public
‣ Documentation: https://graphile.org/postgraphile/introduction/
‣ Node.js version: v14.15.5 on darwin x64
‣ Join Mark in supporting PostGraphile development: https://graphile.org/sponsor/
* * *
However when I go to http://localhost:5000/graphql I have an error on the screen:
{"errors":[{"message":"Only POST requests are allowed."}]}
You're visiting the /graphql endpoint which speaks GraphQL (over POST requests), but you're sending it a web request (over GET). Instead, use the /graphiql end point to view the GraphiQL GraphQL IDE - this endpoint speaks web, and will give you a nice interface for communicating with the /graphql endpoint. See this output from the PostGraphile command:
‣ GraphQL API: http://localhost:5000/graphql
‣ GraphiQL GUI/IDE: http://localhost:5000/graphiql (RECOMMENDATION: add '--enhance-graphiql')
I recommend you add the --enhance-graphiql option to the PostGraphile CLI to get an even more powerful IDE in the browser.
It is because when you type in your address into the address bar of your browser, a GET request is being sent, while your Postgraphile instance only accepts POST requests. So this is the problem. You either avoid sending GET requests, or try and ensure that Postraphile accepts GET requests as well.
A very simple solution would be to create a very simple and small website that will act as a proxy and upon load, it would send a POST request to http://localhost:5000/graphql
There is a GitHub ticket where a middleware is suggested, read this for further information: https://github.com/graphile/postgraphile/issues/442

Dialogflow authentication API v2 - HTTP POST

I´m using dialogflow with http request on a project that works in twilio, with the recent need of migration to v2 API of dialogflow the client access token will not work. Reading the new authentication, I generated the json following the instructions in the google cloud docs, but can´t make it works. Because I need to do all the interaction through POST requests to the dialogflow agent, does anyone know how I can generate the authentication token well?
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
Thanks
This is the function code that today works to make the http request. The problem is that all the services are in Twilio and i dont have access to the server, for that I cant define the environment variable.
Twilio Function code
Twilio Fuctions uses NodeJs and allow me to install many npm modules, with the following limitation: "Native Packages Not Supported - Functions does not provide a C/C++ compliler required to complie native addon modules. This means modules that depend on node-gyp can not be installed to Functions."
I don´t know if this limitations affect service acount working to me in this case.

Azure API Powershell

I am setting up automated deployment pipeline for my website ,as part of it i have to automate Api import using VSTS RM . I have achieved this using custom PS scripts in VSTS tasks. I have used swagger url to import
i.e
Import-AzureRmApiManagementApi –Context $apimContext –SpecificationFormat 'swagger' –SpecificationUrl 'http://mywebapp.com/swagger/docs/v1' –Path 'apis'
To Improve the security we have implemented to redirect the http request https which is secured by client certificate. Here comes the problem.
Now we are not able to use above command to import which is returning 403 forbidden error as API manager don't have option to bypass certificate validation. what can be done to solve this ?
Even i have tried to invoke-webrequest the url with specific cert and to import the API which worked fine in my local machine.
$swaggerurl="https://mywebapp.org/swagger/docs/1"
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("xyz.cer")
$test=Invoke-WebRequest -Uri "$swaggerurl" -Certificate $cert
$test.statuscode
Import-AzureRmApiManagementApi –Context $apimContext –SpecificationFormat 'swagger' –SpecificationUrl 'http://mywebapp.com/swagger/docs/v1' –Path 'apis'
But not in VSTS Inline power shell. It is not accepting certificate value and returning 403 forbidden error.
Please let me know how to resolve this ?
Issue :
1.Unable to import to API manager due to https client certificate validation on swagger url.
VSTS inline power shell not accepting certificate parameter details even though i use the right cert. Same case works in local machine. is there any limitation in VSTS inline power shell.
Thanks in advance.
Using Azure PowerShell step/task instead. (Include in Deploy category)
For this to work, API Management service needs to make the WebRequest on your behalf to the url, with a ClientCertificate in the Request.
We currently don't provide that option to call Import-AzureRmApiManagementApi with a Client Certificate.
Only available option is to make WebRequest using Powershell (Invoke-RestMethod), download the swagger to a local file and use the -SpecificationPath parameter in the cmdlet
This issue has been resolved by changing the private agent to run as admin account. Now Everything works as expected :)
Import of API using VSTS private agent

Not able to create accounts for Private Ethereum Blockchain using Geth and Web3 API

I am unable to create accounts for Private Ethereum Blockchain using Geth and Web3 API.
personal.newAccount(passwd) is not working for me. Please explain how to create account using above command.
And also, I am unable to install "ethereumjs-accounts".
If you try to search the internet why the "geth json rpc personal api" is not working, you will find an excellent answer on Ethereum Stack Exchange which I'd like to quote in full:
First, a note on safety:
You should not make the personal API available over RPC
If you are on a local, trusted machine, you should use IPC instead of RPC. Otherwise, anyone who can connect to your node via RPC can try to brute-force your passwords and steal your Ether.
All administrative APIs are available by default over IPC, so no need to use any flags with geth
To connect via IPC:
Install my library:
npm install web3_extended
var web3_extended = require('web3_extended');
var options = {
host: '/home/user/.ethereum/geth.ipc',
ipc:true,
personal: true,
admin: false,
debug: false
};
var web3 = web3_extended.create(options);
web3.personal.newAccount("password",function(error,result){
if(!error){
console.log(result);
}
});
Replace the host variable with the proper path for your system.
Note: All requests via IPC must be asynchronous.
Some Alternatives:
I don't know why you want to create new accounts via web3, but it's likely not the best way to do what you're trying to achieve. It is much safer and more modular to use a hooked web3 provider with a client-side light wallet or to simply use the Mist browser which handles all accounts for you.
Now for the technique (don't do this)
You need to enable the personal API over RPC. Do this by starting geth with
geth --rpc --rpcapi "db,eth,net,web3,personal"
Then you can use the personal_newAccount method via RPC. It's not implemented in web3.js, so you need to manually issue the RPC request. For example with curl:
curl -X POST --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["password"],"id":1}' localhost:8545
creates a new account with password password and returns the address:
{"id":1,"jsonrpc":"2.0","result":"0x05ca0ddf7e7506672f745b2b567f1d33b7b55f4f"}
There is some basic documentation
Alternatively:
Use the unofficial extended web3.js
this allows you to use the personal, admin and miner APIs via a standard web3.js interface.
Published on Feb 16 at 8:34 and released under terms of CC BY-SA 3.0 by Tjaden Hess.
The command must be personal.newAccount()
Then the console asks for passphrase, give your required password then it again asks for confirmation.
An output in the form of Address("0x----------------------------") will appear.It is 1 account/address for your private network.

ejabberd contribution mod_apns does not work

I have added mod_apns to my ejabberd server. You can find this module here.
my ejabberd.yml configuration is like this:
mod_apns:
address: "gateway.sandbox.push.apple.com"
port: 2195
certfile: "/Applications/ejabberd-15.10/conf/cert.pem"
keyfile: "/Applications/ejabberd-15.10/conf/key.pem"
password: "myPassword"
the address is sandbox since I am still in development phase. And I have tested my cert.pem and key.pem and they are valid and working.
I send my device token to ejabberd server like this:
<iq type="set" to="myEjabberdServer.com">
<register xmlns="https://apple.com/push">
<token>myDeviceTokenWithoutAnySpace</token>
</register>
</iq>
I can see my device token is saved in apns_users database.
But I still do not get notifications when my user is offline.
Am I doing anything wrong?
Does it work with gateway.sandbox.push.apple.com?
should my device token be without space and only characters?
I appreciate your help..
You have asked for an alternate approach. This alternate approach takes the process of triggering push notifications by the ejabberd server.
1. Use the mod_interact library. This will provide you an ability to transfer your messages to another url.
2. From there on you can use the direct HTTP call for push notifications