func formatName(user tgbotapi.User) string {
	firstName := markdownEscape(user.FirstName)
	lastName := markdownEscape(user.LastName)
	return strings.Trim(fmt.Sprintf("%s %s", firstName, lastName), " ")
}
formatName returns the markdown safe version of the user full name in the
form "Firstname Lastname".
package main
import (
	"bytes"
	"encoding/json"
	"fmt"
	"github.com/go-telegram-bot-api/telegram-bot-api"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
	"strings"
)
func safeWriteJSON(data interface{}, file string) error {
	buf, err := json.Marshal(data)
	if err != nil {
		return err
	}
	datadir, err := dataDir()
	if err != nil {
		return err
	}
	tmpfile, err := ioutil.TempFile(datadir, "safe-write")
	if err != nil {
		log.Printf("safeWriteJSON: error creating temp file to save data: %v", err)
		return err
	}
	defer os.Remove(tmpfile.Name())
	if _, err = tmpfile.Write(buf); err != nil {
		log.Printf("safeWriteJSON: error writing data to temp file: %v", err)
		return err
	}
	if err = tmpfile.Close(); err != nil {
		log.Printf("safeWriteJSON: error closing temp file with data: %v", err)
		return err
	}
	f := filepath.Join(datadir, file)
	return os.Rename(tmpfile.Name(), f)
}
func readFromJSON(data interface{}, file string) error {
	buf, err := ioutil.ReadFile(file)
	if err != nil {
		return err
	}
	return json.Unmarshal(buf, data)
}
func readJSONFromDataDir(data interface{}, file string) error {
	datadir, err := dataDir()
	if err != nil {
		return err
	}
	f := filepath.Join(datadir, file)
	return readFromJSON(data, f)
}