Skip to content

Instantly share code, notes, and snippets.

🦈
Shark

Salvatore Cordiano salvatorecordiano

View GitHub Profile
View webhook.php
<?php
header('Content-Type: application/json');
$content = file_get_contents('php://input');
$update = json_decode($content, true);
if (!$update) {
exit;
}
$chatId = $update['message']['chat']['id'] ?? null;
@salvatorecordiano
salvatorecordiano / prepare-commit-msg
Last active Nov 21, 2017
Prepending Git commit messages with Jira IDs
View prepare-commit-msg
#!/bin/bash
# curl -s https://gist.githubusercontent.com/salvatorecordiano/ff73d811c8933c08ea68c1177f3db6c9/raw/6312ceaa840928164afa06e0e42968753b745f61/prepare-commit-msg > .git/hooks/prepare-commit-msg && chmod +x .git/hooks/prepare-commit-msg
COMMIT_MESSAGE=$(cat $1)
PRECOMMIT_MESSAGE=$(git symbolic-ref --short HEAD | grep -Eo "[A-Z0-9]+-[A-Z0-9]+")
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
if [ ! -z "$PRECOMMIT_MESSAGE" ]; then
@salvatorecordiano
salvatorecordiano / response.json
Created Sep 11, 2017
Sample Telegram response
View response.json
{
"update_id": 111111111,
"message": {
"message_id": 1,
"from": {
"id": 01234567890,
"is_bot": false,
"first_name": "Steve",
"last_name": "Jobs",
"username": "stevejobs",
View requestPhoneNumber.php
<?php
$chatId = '---YOUR USER ID---';
$request = [
'chat_id' => $chatId,
'text' => 'Fai tap su condividi numero telefonico',
'reply_markup' => [
'keyboard' => [
[
View webhook.php
<?php
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (! $update) {
exit;
}
$chatId = $update['message']['chat']['id'] ?? null;
View execute.php
<?php
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if(! $update) {
exit;
}
$chatId = $update['message']['chat']['id'] ?? null;
$text = $update['message']['text'] ?? null;
View execute.php
<?php
// recupero il contenuto inviato da Telegram
$content = file_get_contents("php://input");
// converto il contenuto da JSON ad array PHP
$update = json_decode($content, true);
// se la richiesta è null interrompo lo script
if(!$update)
{
exit;
}
View execute.php
<?php
// recupero il contenuto inviato da Telegram
$content = file_get_contents("php://input");
// converto il contenuto da JSON ad array PHP
$update = json_decode($content, true);
// se la richiesta è null interrompo lo script
if(!$update)
{
exit;
}
@salvatorecordiano
salvatorecordiano / webhook.php
Last active Mar 14, 2019
Sample Facebook Bot (1)
View webhook.php
<?php
require_once (dirname(__FILE__) . '/config.php');
require_once (dirname(__FILE__) . '/FacebookBot.php');
$bot = new FacebookBot(FACEBOOK_VALIDATION_TOKEN, FACEBOOK_PAGE_ACCESS_TOKEN);
$bot->run();
$messages = $bot->getReceivedMessages();
foreach ($messages as $message)
{
$recipientId = $message->senderId;
if($message->text)
@salvatorecordiano
salvatorecordiano / execute.php
Last active Sep 19, 2017
Sample Telegram Bot (4)
View execute.php
<?php
// insert here your Bot API token
define("BOT_TOKEN", "...");
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if(!$update)
{
exit;
}
$message = isset($update['message']) ? $update['message'] : "";
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.