Exemple #1
0
	void SendNotification(CModule& module, const CString& sSender, const CString& sNotification, const CChan *pChannel) {
		// todo parse from m_sPushEndpoint
		bool bUseTLS = true;
		CString sHostname = "api.palaverapp.com";
		unsigned short uPort = 443;
		CString sPath = "/1/push";

		CString sJSON = "{";
		sJSON += "\"message\": \"" + sNotification.Replace_n("\"", "\\\"") + "\"";
		sJSON += ",\"sender\": \"" + sSender.Replace_n("\"", "\\\"") + "\"";
		if (pChannel) {
			sJSON += ",\"channel\": \"" + pChannel->GetName().Replace_n("\"", "\\\"") + "\"";
		}
		sJSON += "}";

		CSocket *pSocket = new CSocket(&module);
		pSocket->Connect(sHostname, uPort, bUseTLS);
		pSocket->Write("POST " + sPath + " HTTP/1.1\r\n");
		pSocket->Write("Host: " + sHostname + "\r\n");
		pSocket->Write("Authorization: Bearer " + GetToken() + "\r\n");
		pSocket->Write("Connection: close\r\n");
		pSocket->Write("User-Agent: ZNC\r\n");
		pSocket->Write("Content-Type: application/json\r\n");
		pSocket->Write("Content-Length: " + CString(sJSON.length()) + "\r\n");
		pSocket->Write("\r\n");
		pSocket->Write(sJSON);
		pSocket->Close(Csock::CLT_AFTERWRITE);
		module.AddSocket(pSocket);
	}